jQuery,checkboxes and .is(":checked") [英] jQuery, checkboxes and .is(":checked")
问题描述
当我将一个函数绑定到一个复选框元素如:
$(#myCheckbox ){
alert($(this).is(:checked));
});
复选框会在触发事件之前更改其选中的属性
$ b
但是,当我这样做:
code> $(#myCheckbox)。click();
复选框在触发事件后选中属性 p> 我的问题是,是否有一种方法来触发来自jQuery的点击事件,像正常的点击会做的(第一种情况)? PS:我已经尝试过 我认为你应该使用更改处理程序: When I bind a function to a checkbox element like: The checkbox changes its checked attribute before the event is triggered, this is the normal behavior, and gives an inverse result. However, when I do: The checkbox changes it checked attribute after the event is triggered. My question is, is there a way to trigger the click event from jQuery like a normal click would do (first scenario)? PS: I've already tried with I would think you should use the "change" handler instead:
这篇关于jQuery,checkboxes and .is(":checked")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
trigger('click')
;
$('#myCheckbox' ).change(function(){
if($(this).attr(checked)){
// checked
return;
} / not checked
});
$("#myCheckbox").click( function() {
alert($(this).is(":checked"));
});
$("#myCheckbox").click();
trigger('click')
;$('#myCheckbox').change(function () {
if ($(this).attr("checked")) {
// checked
return;
}
// not checked
});