如何查看您是否两次点击相同的元素?jQuery的

Tay*_*Mac 5 jquery this jquery-selectors

如何检测用户是否点击了相同的div?

我试过这个没有成功:

    _oldthis = null;

    var _this = $(this);

    if(_oldthis == _this) {
        alert('You clicked this last');
    }

    _oldthis = _this;
Run Code Online (Sandbox Code Playgroud)

ick*_*fay 14

您无法比较jQuery对象,但可以比较它们包含的DOM对象.试试这个:

var previousTarget=null;
$("a").click(function() {
    if(this===previousTarget) {
        alert("You've clicked this element twice.");
    }
    previousTarget=this;
    return false;
});
Run Code Online (Sandbox Code Playgroud)