动态删除select中的全部options:
document.getElementById("ddlResourceType").options.length=0;app
动态删除select中的某一项option:
document.getElementById("ddlResourceType").options.remove(indx); 测试
动态添加select中的项option:
document.getElementById("ddlResourceType").options.add(new Option(text,value));rem
上面在IE和FireFox都能测试成功,但愿之后你能够用上。
其实用标准的DOM操做也能够,就是document.createElement,appendChild,removeChild之类的。get
取值方面
function getvalue(obj)
{
var m=obj.options[obj.selectedIndex].value
alert(m);//获取value
var n=obj.options[obj.selectedIndex].text
alert(n);//获取文本
}io
==============================================================================
1 检测是否有选中
if (objSelect.selectedIndex > - 1 ) {
// 说明选中
} else {
// 说明没有选中
}function
将option设为选中:document.getElementById("province").options.selected = true;select
2 删除被选中的项
objSelect.options[objSelect.selectedIndex] = null ;vi
3 增长项
objSelect.options[objSelect.length] = new Option( " 你好 " , " hello " );document
4 修改所选择中的项
objSelect.options[objSelect.selectedIndex] = new Option( " 你好 " , " hello " );new
5 获得所选择项的文本
objSelect.options[objSelect.selectedIndex].text;
6 获得所选择项的值 objSelect.options[objSelect.selectedIndex].value;