JavaScript控制ComboBox中Option的增加和删除(原)

 1<html>
 2<head>
 3<title> Demo </title>
 4<script   language=javascript>
 5function   deloption(){   
 6    var   obj=document.getElementById("sel").options; 
 7
 8    if (obj.length > 1){
 9        obj.options.remove(obj.length - 1);   
10    }
   
11}
   
12
13function   addoption()   
14{
15    var   obj=document.getElementById("sel").options; 
16    var   opt   =   new   Option("newoption" + obj.length, obj.length ); 
17    obj.options.add(opt);   
18
19}

20</script>
21</head>
22<body>
23<select name="sel">
24    <option>one
25</select>
26<input type="button" onclick="addoption()" value="ADD">
27<input type="button" onclick="deloption()" value="DEL">
28</body>
29</html>
原文地址:https://www.cnblogs.com/meil/p/576755.html