jQuery检查是否单击 [英] jQuery check if it is clicked or not
本文介绍了jQuery检查是否单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$( element ).click( function() {
});
如何检查元素是否被单击?我就是那样
How can I check if the element is clicked or not? I'm doing like that
function element() {
$( "#element" ).click( function() {
return 0;
} );
}
if( element() == 0 ) {
alert( "yes" );
} else {
alert( "no" );
}
但是它什么也没返回.
推荐答案
您可以使用 .data()
:
$("#element").click(function(){
$(this).data('clicked', true);
});
,然后使用以下命令进行检查:
and then check it with:
if($('#element').data('clicked')) {
alert('yes');
}
要获得更好的答案,您需要提供更多信息.
To get a better answer you need to provide more information.
更新:
根据您的评论,我了解您想要以下内容:
Based on your comment, I understand you want something like:
$("#element").click(function(){
var $this = $(this);
if($this.data('clicked')) {
func(some, other, parameters);
}
else {
$this.data('clicked', true);
func(some, parameter);
}
});
这篇关于jQuery检查是否单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文