曲奇饼 发表于 2020-3-16 12:40:02

得到select所有option里的值

1://取得所有的option个数
document.getElementById('---').options.length

2://取得每个option的ID值
document.getElementById('---').options.value

3://取得每个option在页面显示的文本
document.getElementById('---').options.text

4://判断该option是否被选中
document.getElementById('---').options.selected == true

5://设置该option为选中
document.getElementById('---').options.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=newOption;

页: [1]
查看完整版本: 得到select所有option里的值