我有一个选择输入:
<select size="1" name="filter" style="width:90px;" id="priority_filter" onchange="filter_user_trainings();">
<option value="all">All</option>
<option value="optional">Optional</option>
<option value="mandatory">Mandatory</option>
<option value="essential">Essential</option>
<option value="custom">Custom</option>
</select>
<div style="width: 50%; text-align: right; float: right">
<input type="checkbox" id="opt_box" onchange="somestuff()">Optional
<input type="checkbox" id="mand_box" onchange="somestuff()" checked="checked">Mandatory
<input type="checkbox" id="ess_box" onchange="somestuff()">Essential
</div>
和一个jQuery代码:
switch(priority_filter){
case 'all':
$("#opt_box").attr({checked: "checked"});
$("#mand_box").attr({checked: "checked"});
$("#ess_box").attr({checked: "checked"});
break;
case 'optional' :
$("#opt_box").attr({checked: "checked"});
$("#mand_box").removeAttr("checked");
$("#ess_box").removeAttr("checked");
break;
case 'essential' :
$("#ess_box").attr({checked: "checked"});
$("#mand_box").removeAttr("checked");
$("#opt_box").removeAttr("checked");
break;
case 'mandatory' :
$("#mand_box").attr({checked: "checked"});
$("#opt_box").removeAttr("checked");
$("#ess_box").removeAttr("checked");
case 'custom' :
$("#mand_box").attr({checked: "checked"});
$("#opt_box").removeAttr("checked");
$("#ess_box").removeAttr("checked");
break;
}
我想在“onchange”属性中调用该函数。当js切换复选框的值但它不起作用时。我该如何解决?