我有以下几点:
$(document).ready(function()
{
$("#select-all-teammembers").click(function() {
$("input[name=recipients\\[\\]]").attr('checked', true);
});
});
我希望id="select-all-teammembers"在选中和未选中之间切换。想法吗?那不是几十行代码吗?
我有以下几点:
$(document).ready(function()
{
$("#select-all-teammembers").click(function() {
$("input[name=recipients\\[\\]]").attr('checked', true);
});
});
我希望id="select-all-teammembers"在选中和未选中之间切换。想法吗?那不是几十行代码吗?
当前回答
你可以简单地使用它
$("#chkAll").on("click",function(){
$("input[name=checkBoxName]").prop("checked",$(this).prop("checked"));
});
其他回答
您还可以通过执行以下操作来切换复选框。目前使用引导切换复选框。
<link href='https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css' rel='stylesheet'>
<script src='https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js'></script>
<input type='checkbox' id='toggleScheduler' name='toggleScheduler' data-toggle='toggle' data-on='Enabled' data-off='Disabled'
$("#toggleScheduler").bootstrapToggle('on'); // enable toggle checkbox
$("#toggleScheduler").bootstrapToggle('off'); // disable toggle checkbox
有一个更简单的方法
首先给你的复选框一个类示例'id_chk'
然后在复选框内,将控制'id_chk'复选框的状态put:
<输入类型='checkbox' onchange='js:jQuery(.id_chk)。道具(“检查”、j查询(this)、道具(“检查”)' />
就这些,希望这能有所帮助
jQuery("#checker").click(function(){
jQuery("#mydiv :checkbox").each(function(){
this.checked = true;
});
});
jQuery("#dechecker").click(function(){
jQuery("#mydiv :checkbox").each(function(){
this.checked = false;
});
});
jQuery("#checktoggler").click(function(){
jQuery("#mydiv :checkbox").each(function(){
this.checked = !this.checked;
});
});
;)
使用这个插件:
$.fn.toggleCheck =function() {
if(this.tagName === 'INPUT') {
$(this).prop('checked', !($(this).is(':checked')));
}
}
然后
$('#myCheckBox').toggleCheck();
假设它是一个必须切换复选框的图像,这对我来说是可行的
<img src="something.gif" onclick="$('#checkboxid').prop('checked', !($('#checkboxid').is(':checked')));">
<input type="checkbox" id="checkboxid">