jQuery:如何捕获来自输入[type ='checkbox']的更改事件(如果是以编程方式检查)? [英] jQuery: How to catch change event from input[type='checkbox'] if it was checked programmatically?

查看:144
本文介绍了jQuery:如何捕获来自输入[type ='checkbox']的更改事件(如果是以编程方式检查)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< input type =checkboxid =check1/>
如果从脚本ie $('#check1')更改了此复选框的更改事件attr ','checked');

I've got an <input type="checkbox" id="check1" />. How to catch change event for this checkbox if it was changed from script i.e. $('#check1').attr('checked', 'checked');?

谢谢。

推荐答案

Javascript不会根据表单元素的程序化更改触发事件 - 以防止无限循环的事件 - 因此您有两个(不太理想)选项:

Javascript doesn't fire events based on programmatic changes to form elements - to prevent infinite loops of events - so you have two (less-than-ideal) options:


  • 编写更改属性的包装函数,然后强制自己始终使用包装函数

  • 只要在更改属性时自己调用回调

  • Write a wrapper function which changes the attribute and calls your callback, and then force yourself to always use your wrapper function
  • Just call the callback yourself when you change the attribute

这篇关于jQuery:如何捕获来自输入[type ='checkbox']的更改事件(如果是以编程方式检查)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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