JavaScript Reference/Javascript Collections/options

Материал из Web эксперт
Перейти к: навигация, поиск

"options" Example

   <source lang="javascript">
   

<html> <body> <select id="mySelect">

   <option>List Item 1</option>
   <option>List Item 2</option>
   <option>List Item 3</option>

</select> <button onclick="alert(mySelect.options.length);">Number of options in the select list</button> </body> </html>


     </source>
   
  


"options" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |<select> | +----------------+--------------------------------------------------------------+

     </source>
   
  


"options" JavaScript properties and JavaScript methods

   <source lang="javascript">

JavaScript properties and JavaScript methods

add(), item(), length, namedItem(), remove(), tags(), urns()


     </source>
   
  


"options" Syntax Parameters and Note

   <source lang="javascript">

Note: Returns an array of all the <option> elements in a <select>.

Syntax:

document.getElementById("selectID").options // returns all options document.getElementById("selectID").options(param1, param2) // returns an individual option document.all.selectID.options // IE only document.all.selectID.options(param1, param2) // IE only Parameters:

   param1   Required; zero-based index or
                      desired member"s id or name attribute.
                      
   param2   Optional; the zero-based index for the result returned
                      if param1 matches more than one element.
     
     </source>