捕获复选框的选中的更改事件 [英] Catch checked change event of a checkbox

查看:119
本文介绍了捕获复选框的选中的更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery捕获<input type="checkbox" />的检查/取消检查事件?

How do I to catch check/uncheck event of <input type="checkbox" /> with jQuery?

推荐答案

<input type="checkbox" id="something" />

$("#something").click( function(){
   if( $(this).is(':checked') ) alert("checked");
});

如果复选框由于除单击之外的其他原因(例如使用键盘)而更改,则此操作将无法捕获.为避免此问题,请听change而不是click.

Doing this will not catch when the checkbox changes for other reasons than a click, like using the keyboard. To avoid this problem, listen to changeinstead of click.

要以编程方式检查/取消检查,请查看为什么不是我的复选框更改事件已触发?

For checking/unchecking programmatically, take a look at Why isn't my checkbox change event triggered?

这篇关于捕获复选框的选中的更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆