如何处理更改复选框使用jQuery? [英] How to handle change of checkbox using jQuery?
本文介绍了如何处理更改复选框使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些代码
<input type="checkbox" id="chk" value="value" />
<label for="chk">Value </label>
<br/>
<input type="button" id="But1" value="set value" />
<br />
<input type="button" id="But2" value="read checked" />
javascript:
javascript:
$(document).ready(function () {
console.log("Ready ...");
registerHandlers();
function registerHandlers() {
$('#But1').click(function () {
$('#chk').prop('checked', !$('#chk').is(':checked'));
});
$('#But2').click(function () {
var chk1 = $('#chk').is(':checked');
console.log("Value : " + chk1);
});
$('input[type="checkbox"]').change(function () {
var name = $(this).val();
var check = $(this).prop('checked');
console.log("Change: " + name + " to " + check);
});
}
});
如何使用jQuery处理更改复选框?
How to handle change of checkbox using jQuery ? I need to put the handler to change any checkboxes checked.
[update]
是一个复选框和几个按钮。
每个按钮都可以更改复选框。
如何捕获改变复选框的事件?
There is a checkbox and a few buttons. Each button can change check box. How to catch an event changing the checkbox?
[Update]
在此示例中,我需要处理更改复选框 jsfiddle 。
I need handle change checkbox in this example jsfiddle. When I click on the box the message "OK" button is not shown.
推荐答案
使用当我点击框时,不会显示 http://api.jquery.com/checkbox-selector/> :checkbox
选择器:
Use :checkbox
selector:
$(':checkbox').change(function() {
// do stuff here. It will fire on any checkbox change
});
代码: http: //jsfiddle.net/s6fe9/
这篇关于如何处理更改复选框使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文