我想这样做,使用jQuery勾选复选框:
$(".myCheckBox").checked(true);
or
$(".myCheckBox").selected(true);
这样的事情存在吗?
我想这样做,使用jQuery勾选复选框:
$(".myCheckBox").checked(true);
or
$(".myCheckBox").selected(true);
这样的事情存在吗?
当前回答
如果您碰巧在使用Bootstrap(可能是无意中)。。。
$('#myCheckbox').bootstrapToggle('on')
$('#myCheckbox').bootstrapToggle('off')
http://www.bootstraptoggle.com/
其他回答
对于jQuery 1.6+
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);
对于jQuery 1.5.x及以下版本
$('.myCheckbox').attr('checked', true);
$('.myCheckbox').attr('checked', false);
为了检查,
$('.myCheckbox').removeAttr('checked');
选中和取消选中
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);
你可以试试这个:
$('input[name="activity[task_state]"]').val("specify the value you want to check ")
这是完整的答案使用jQuery
我测试了它,它100%工作:D
// when the button (select_unit_button) is clicked it returns all the checed checkboxes values
$("#select_unit_button").on("click", function(e){
var arr = [];
$(':checkbox:checked').each(function(i){
arr[i] = $(this).val(); // u can get id or anything else
});
//console.log(arr); // u can test it using this in google chrome
});
$(".myCheckBox").prop("checked","checked");