$( element ).click( function() {
});
如何检查元素是否被点击?我就是这么做的
function element() {
$( "#element" ).click( function() {
return 0;
} );
}
if( element() == 0 ) {
alert( "yes" );
} else {
alert( "no" );
}
但它没有返回任何内容。
最佳答案
您可以使用.data()
:
$("#element").click(function(){
$(this).data('clicked', true);
});
然后用以下命令检查:
if($('#element').data('clicked')) {
alert('yes');
}
为了获得更好的答案,您需要提供更多信息。
更新:
根据您的评论,我知道您想要以下内容:
$("#element").click(function(){
var $this = $(this);
if($this.data('clicked')) {
func(some, other, parameters);
}
else {
$this.data('clicked', true);
func(some, parameter);
}
});
关于jQuery 检查是否被点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6081608/