動態刪除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;