📜  HTML | DOM Select selectedIndex 属性

📅  最后修改于: 2021-10-29 05:59:37             🧑  作者: Mango

HTML DOM 中的Select selectedIndex 属性用于设置或返回下拉列表中所选选项的索引。下拉列表的索引一般从0开始,如果没有选择任何选项则返回-1。如果下拉列表允许多项选择,则此属性返回第一个选项的索引。

句法:

  • 它返回 Select selectedIndex 属性。
    selectObject.selectedIndex
  • 它用于设置 Select selectedIndex 属性。
    selectObject.selectedIndex = number 

属性值:它包含单个值编号,用于指定下拉列表中所选选项的索引。

下面的程序说明了 HTML DOM 中的 Select selectedIndex 属性:

示例:本示例使用 Select selectedIndex 属性来选择索引为“3”的



      
 
    
        HTML DOM Select selectedIndex Property
     

  

  
    

        GeeksforGeeks     

             

        Select selectedIndex Property     


           Select your preferred course from the drop-down list:
                       

        To select the option element with index "3",         double-click the "Return Element" button.     

                                                                                     

输出:
点击按钮前:

点击按钮后:

支持的浏览器: DOM Select selectedIndex 属性支持的浏览器如下:

  • 苹果Safari
  • IE浏览器
  • 火狐
  • 谷歌浏览器
  • 歌剧