js 得到select所有option里的值

来源:互联网 发布:单片机计时器原理 编辑:程序博客网 时间:2024/06/07 08:34
1://取得所有的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;

0 0
原创粉丝点击