<button id="btn1a" type="button">启用</button>
<button id="btn1b" type="button">禁用</button>
<button id="btn2a" type="button">可多选</button>
<button id="btn2b" type="button">不可多选</button>
<button id="btn3a" type="button">size=1</button>
<button id="btn3b" type="button">size=2</button>
<button id="btn3c" type="button">size=3</button>
<button id="btn3d" type="button">不设置size</button>
<form action="#">
<br><br>
<select name="test" id="select">
<optgroup label="num">
<option value="11" disabled>1</option>
<option value="22" selected>2</option>
<option value="33">3</option>
<option value="44" label="word">4</option>
</optgroup>
<optgroup label="word">
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</optgroup>
<optgroup label="汉字" disabled>
<option value="一个">一</option>
<option value="二个">二</option>
<option value="三个">三</option>
<option value="四个">四</option>
</optgroup>
</select>
<input type="submit">
</form>
<script>
var select = document.getElementById('select');
btn1a.onclick = function(){
select.removeAttribute('disabled');
}
btn1b.onclick = function(){
select.setAttribute('disabled','');
}
btn2a.onclick = function(){
select.setAttribute('multiple','');
}
btn2b.onclick = function(){
select.removeAttribute('multiple');
}
btn3a.onclick = function(){
select.setAttribute('size','1');
}
btn3b.onclick = function(){
select.setAttribute('size','2');
}
btn3c.onclick = function(){
select.setAttribute('size','3');
}
btn3d.onclick = function(){
select.removeAttribute('size');
}
</script>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。