我有一个选择输入:管理复选框功能使用jQuery
<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;
}
我要调用的函数,在 “平变化” ATTR。当js切换复选框的值,但它不起作用。我该如何解决它?
对'IE'(lt 8)出了名的错误,因为'click'事件是一个有效的选择。 – 2013-04-10 13:44:54
是否可以使它仅与onclick或onchange或sg一起使用? – csaron92 2013-04-10 13:49:46
你可以在'somestuff()'函数中调用'onChange'函数,只在你的函数中使用if($(“#checkBoxId”)。is(':checked')){ // do your在这里工作 }' – 2013-04-10 13:52:19