当启用 id 为“exactage”的复选框时,我想使用 javascript 将属性disabled=“disabled”设置为 id 年龄为 2。有任何想法吗?提前致谢。一个快乐的编码员:)
<select id="age">
<option value="18"><18</option>
</select>
<select id="age2">
<option value="18"><18</option>
</select>
<input type="checkbox" id="exactage"/> Require exact age
最佳答案
如果启用意味着已选中
if(document.getElementById('exactage').checked)
document.getElementById('age2').setAttribute('disabled', 'disabled');
如果“启用”实际上是指“启用”,则可以执行以下操作:
if(document.getElementById('exactage').getAttribute('disabled') !== null)
document.getElementById('age2').setAttribute('disabled', 'disabled');
关于php - 启用复选框时禁用 <select>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8673923/