美好的一天,
目标
从下拉列表中选择的特定值更改道具或属于复选框。
我现在的例子。我希望当选择橙色时禁用方框1并启用2& 3,当选择苹果时启用方框1并禁用方框2和3等...
谢谢
HTML
<table>
<tr>
<td>
<input type="checkbox" name="1" id="1"/>1:</td>
<td>
<input type="checkbox" name="2" id="2"/>2:</td>
<td>
<input type="checkbox" name="3" id="3"/>3:</td>
<td>
<select id="CheckThis" name="CHeckThis" onchange="setChkSelect(this.value);">
<option value="null">--Select This--</option>
<option value="orange">orange</option>
<option value="apple">apple</option>
<option value="grappe">grappe</option>
</select>
</td>
</tr>
</table>
JAVASCRIPT
function setChkSelect(value){
var chk1 = document.getElementById('1')
chk1.disabled = (value == 'orange');
var chk2 = document.getElementById('2')
chk2.disabled = (value == 'apple');
chk1.disabled = (value == 'apple');
var chk3 = document.getElementById('3')
chk3.disabled = (value == 'grappe');
chk1.disabled = (value == 'grappe');
}
答案 0 :(得分:0)
没有名为enabled
仅disabled
。只与它一起工作
答案 1 :(得分:0)
这种方法更适合您的要求。
function setChkSelect(){
var ddl = document.getElementById('CheckThis');
var selectedValue = ddl.options[ddl.selectedIndex].value;
var chk1 = document.getElementById('1');
var chk2 = document.getElementById('2');
var chk3 = document.getElementById('3');
if(selectedValue == 'orange'){
chk1.disabled = true;
chk2.disabled = false;
chk3.disabled = false;
}else if(selectedValue == 'apple'){
chk1.disabled = false;
chk2.disabled = true;
chk3.disabled = true;
}else if(selectedValue == 'grappe'){
chk1.disabled = true;
chk2.disabled = false;
chk3.disabled = true;
}else{
chk1.disabled = false;
chk2.disabled = false;
chk3.disabled = false;
}
}
将此方法称为:
<select id="CheckThis" name="CHeckThis" onChange="setChkSelect();">
参见工作示例:http://jsfiddle.net/95w59/