转jQuery checkbox选中、改变状态、change和click事件
2017-05-25前端点击 zqifa 共227字,阅读约需1分钟
jquery判断checked的三种方法:
1 2 3
| .attr('checked'); .prop('checked'); .is(':checked');
|
jquery赋值checked的几种写法:
1 2 3 4 5 6 7 8 9 10 11 12
| $("#cb1").attr("checked", "checked"); $("#cb1").attr("checked", true);
$("#cb1").prop("checked", true); $("#cb1").prop({checked: true}); $("#cb1").prop("checked", function () { return true; });
$("#cb1″).prop("checked","checked");
|
checkbox click和change事件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| $("#ischange").change(function () { alert("checked"); });
$(function () { if ($.browser.msie) { $('input:checkbox').click(function () { this.blur(); this.focus(); }); } });
$("#ischange").change(function () { alert("checked"); });
$(function () { if ($.browser.msie) { $('input:checkbox').click(function () { this.blur(); this.focus(); }); } });
$(document).ready(function () { $("testCheckbox").change(function () { alert("Option changed!"); }); });
|