输入(按钮)检查和取消选中事件(JQuery)(Input (button) check and uncheck event (JQuery))

编程入门 行业动态 更新时间:2024-10-27 08:29:09
输入(按钮)检查和取消选中事件(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 学习jQuery

You 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 selector

Probably you should start with

jQuery API Learn jQuery

更多推荐

本文发布于:2023-08-07 21:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   事件   JQuery   Input   event

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!