案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
function insertOption()
5
  {
6
  var y=document.createElement('option');
7
  y.text='Kiwi'
8
  var x=document.getElementById("mySelect");
9
  try
10
    {
11
    x.add(y,null); // standards compliant
12
    }
13
  catch(ex)
14
    {
15
    x.add(y); // IE only
16
    }
17
  }
18
</script>
19
</head>
20
<body>
21
22
<form>
23
<select id="mySelect">
24
  <option>Apple</option>
25
  <option>Pear</option>
26
  <option>Banana</option>
27
  <option>Orange</option>
28
</select>
29
<input type="button" onclick="insertOption()" value="Insert option" />
30
</form>
31
32
</body>
33
</html>
34