是否可以更改复选框状态而不会导致点击事件? [英] Is it possible to change checkbox state without causing click event?

查看:211
本文介绍了是否可以更改复选框状态而不会导致点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来阻止输入[type ='checkbox'] 触发点击


解决方案

如果在 checked 属性上使用 .prop(),则不会触发点击事件: / p>

  $(input [type ='checkbox']复选框点击'); 
});
$('#mycheckbox')。prop('checked',true);
$('#mycheckbox')。prop('checked',false);
$('#mycheckbox')。prop('checked',true);
$('#mycheckbox')。prop('checked',false);
$('#mycheckbox')。prop('checked',true);

http://jsbin.com/ecIqu​​le/3/edit


I'm trying to find a way to prevent input[type='checkbox'] from triggering the click event when I change his state with jquery.

Is it possible?

解决方案

If you use .prop() on the checked attribute, no click event will be triggered:

$("input[type='checkbox']").click(function() {
  alert('checkbox clicked');
});
$('#mycheckbox').prop('checked', true);
$('#mycheckbox').prop('checked', false);
$('#mycheckbox').prop('checked', true);
$('#mycheckbox').prop('checked', false);
$('#mycheckbox').prop('checked', true);

http://jsbin.com/ecIQUle/3/edit

这篇关于是否可以更改复选框状态而不会导致点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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