输入(按钮)检查和取消选中事件(JQuery)(Input (button) check and uncheck event (JQuery))
我需要做不同的事情,具体取决于是否通过鼠标选中或取消选中具有ID属性的复选框。 执行检查或取消选中时,需要触发事件。 我想可以使用单个检查事件处理程序,只是看看检查状态是什么,但我不知道如何。
I need to do different things depending on whether a checkbox with an ID attribute is checked or unchecked by a mouse. An event needs to be fired when either a check or an uncheck is performed. I suppose one could use a single check event handler and just see what the check state is but I don't know how.
最满意答案
您可以使用在更改复选框状态时将触发的更改事件,因此使用复选框的ID注册更改事件处理程序
//dom ready handler jQuery(function ($) { //change event handler $('#myid').change(function () { if (this.checked) { //checked do something $('span').text('checked'); } else { //unchecked do something else $('span').text('unchecked'); } }) })演示: 小提琴
文件就绪 改变事件 改变事件处理程序 id选择器可能你应该先开始
jQuery API 学习jQueryYou can use the change event which will be fired when the checkbox state is changed, so register a change event handler using the id of the checkbox
//dom ready handler jQuery(function ($) { //change event handler $('#myid').change(function () { if (this.checked) { //checked do something $('span').text('checked'); } else { //unchecked do something else $('span').text('unchecked'); } }) })Demo: Fiddle
Document Ready change event change event handler id selectorProbably you should start with
jQuery API Learn jQuery更多推荐
发布评论