增加option标签与增加其它xhtml标签不同,有两种方法可以实现增加功能;
方法1:
var selectE = document.getElementById("Select1");
var newoption = new [color=red]Option[/color]("777","嘿嘿7");
//Option 一定要大写否则不能实现其功能
selectE.options[selectE.options.length] = newoption;
//在最后增加一个新的option
方法2:
var selectE = document.getElementById("Select1");
var newoption = new [color=red]Option[/color]("777","嘿嘿7");
selectE.add(newoption,selectE.options[0]);
方法1:
var selectE = document.getElementById("Select1");
var newoption = new [color=red]Option[/color]("777","嘿嘿7");
//Option 一定要大写否则不能实现其功能
selectE.options[selectE.options.length] = newoption;
//在最后增加一个新的option
方法2:
var selectE = document.getElementById("Select1");
var newoption = new [color=red]Option[/color]("777","嘿嘿7");
selectE.add(newoption,selectE.options[0]);
本文介绍了两种在XHTML中添加Option标签的方法。方法一通过直接设置Select元素的options属性来添加新的Option项;方法二使用add方法将Option项添加到指定位置。这两种方法均适用于动态更新Select下拉框。
912

被折叠的 条评论
为什么被折叠?



