zoukankan      html  css  js  c++  java
  • selectedIndex 属性

    selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。

    注释:若允许多重选择,则仅会返回第一个被选选项的索引号。

    语法

    selectObject.selectedIndex=number

    实例

    下面的例子可提示出被选选项的索引号:

    <html>
    <head>
    <script type="text/javascript">
    function getIndex()
      {
      var x=document.getElementById("mySelect")
      alert(x.selectedIndex)
      }
    </script>
    </head>
    <body>
    
    <form>
    Select your favorite fruit:
    <select id="mySelect">
      <option>Apple</option>
      <option>Orange</option>
      <option>Pineapple</option>
      <option>Banana</option>
    </select>
    <br /><br />
    <input type="button" onclick="getIndex()"
    value="Alert index of selected option">
    </form>
    
    </body>
    </html>







    <html>
    <head>
    <script type="text/javascript">
    function insertBeforeSelected()
      {
      var x=document.getElementById("mySelect");
      if (x.selectedIndex>=0)
        {
        var y=document.createElement('option');
        y.text='Kiwi';
        var sel=x.options[x.selectedIndex];  
        try
          {
          x.add(y,sel); // standards compliant
          }
        catch(ex)
          {
          x.add(y,x.selectedIndex); // IE only
          }
        }
      }
    </script>
    </head>
    <body>

    <form>
    <select id="mySelect">
      <option>Apple</option>
      <option>Pear</option>
      <option>Banana</option>
      <option>Orange</option>
    </select>
    <input type="button" onclick="insertBeforeSelected()" value="Insert option before selected" />
    </form>

    </body>
    </html>


  • 相关阅读:
    NIOS II常用函数整理
    C指针
    YCbCrYUV
    指针与引用的区别
    Pacman 命令详解
    DDR工作原理
    关于C/C++中的点操作符和箭头操作符
    千兆以太网芯片88E1111 RGMII模式的驱动
    关于建立时间和保持时间
    ECE 576 UDP Hardware
  • 原文地址:https://www.cnblogs.com/jianxingjianyuan/p/6740683.html
Copyright © 2011-2022 走看看