如何查看您是否两次单击同一元素? jQuery的 [英] How to see if you're clicking the same element twice? Jquery
本文介绍了如何查看您是否两次单击同一元素? jQuery的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测用户是否单击了相同的div?
How can you detect if the user is clicking the same div?
我尝试了这个没有成功:
I've tried this with no success:
_oldthis = null;
var _this = $(this);
if(_oldthis == _this) {
alert('You clicked this last');
}
_oldthis = _this;
推荐答案
您不能比较jQuery对象,但是可以比较它们包含的DOM对象.试试这个:
You can't compare jQuery objects, but you can compare the DOM objects they contain. Try this:
var previousTarget=null;
$("a").click(function() {
if(this===previousTarget) {
alert("You've clicked this element twice.");
}
previousTarget=this;
return false;
});
这篇关于如何查看您是否两次单击同一元素? jQuery的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文