var obj = document.getElementById("mySelect"); obj.add(new Option("4","4"));
3、删除所有选项option
代码如下:
var obj = document.getElementById("mySelect"); obj.options.length = 0;
4、删除选中选项option
代码如下:
var obj = document.getElementById("mySelect"); var index = obj.selectedIndex; obj.options.remove(index);
5、修改选中选项option
代码如下:
var obj = document.getElementById("mySelect"); var index = obj.selectedIndex; obj.options[index] = new Option("three",3); //更改对应的值 obj.options[index].selected = true; //保持选中状态
6、删除select
代码如下:
var obj = document.getElementById("mySelect"); obj.parentNode.removeChild(obj); //移除当前对象