js 得到select所有option里的值
document.getElementById('---').options.length
2://取得每個option的ID值
document.getElementById('---').options[i].value
3://取得每個option在頁面顯示的文本
document.getElementById('---').options[i].text
4://判斷該option是否被選中
document.getElementById('---').options[i].selected == true
5://設置該option為選中
document.getElementById('---').options[i].selected = true
6://去掉所有的Option
document.getElementById(daySelectTagName).options.length=0;
7.重新生成Option
//生成新的Option對象
//第一個false表示不默認選中
//第二個false表示只能進行單選
var newOption=new Option(newOptionValue,newOptionValue,false,false);
//將新生成的Option添加到Select標簽中
document.getElementById(daySelectTagName).options[i-1]=newOption;
總結
以上是生活随笔為你收集整理的js 得到select所有option里的值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js定时器
- 下一篇: DIV CSS left right t