案例:javascript案例     状态:可编辑再运行    进入横版
AخA
<input type="button" onclick="insertBeforeSelected()" value="Insert option before selected" />
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
function insertBeforeSelected()
5
  {
6
  var x=document.getElementById("mySelect");
7
  if (x.selectedIndex>=0)
8
    {
9
    var y=document.createElement('option');
10
    y.text='Kiwi';
11
    var sel=x.options[x.selectedIndex];  
12
    try
13
      {
14
      x.add(y,sel); // standards compliant
15
      }
16
    catch(ex)
17
      {
18
      x.add(y,x.selectedIndex); // IE only
19
      }
20
    }
21
  }
22
</script>
23
</head>
24
<body>

 运行结果 
 北美留学生论坛