简体   繁体   English

jQuery持续点击元素...?

[英]jQuery get lasted clicked on element…?

Hey, hope someone can help with this.. 嘿,希望有人可以帮忙。

How can I get the previous ID of a clicked div element using jQuery? 如何使用jQuery获取单击的div元素的先前ID?

Is this even possible? 这有可能吗?

eg I have two div's named div1 and div2 , I click on div1 then on div2 , how can I get the ID of div1? 例如,我有两个div的命名DIV1DIV2,我点击然后DIV2 DIV1,我怎么能得到DIV1的ID?

Many thanks 非常感谢

Store it in a variable. 将其存储在变量中。

var lastClicked = null;

$("div").click(function() {
    if (lastClicked) {
        // use lastClicked here
    }

    // Do current click stuff

    lastClicked = this;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM