$(element).click(function(){}); 如何检查元素是否被点击?我是那样做的 function element(){$("#element").click(function(){ return 0;});}if(element()==0){alert("yes");}else{alert("no");} 但它没有返回任何东西. 你可以
$(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);
}
});
