获取最后点击的ID-jQuery [英] Get the ID of the last clicked - jQuery
本文介绍了获取最后点击的ID-jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个div ...
I have three div's...
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
当我单击随机div时,它将div的顺序移到顶部(例如,让我们使用ID#2).因此,在这一点之后,div可能不按时间顺序排列.下面的示例...
When I click on a random div, it moves the order of the div to the top (Let's use ID #2 for example). So the div's could be out of chronological order after this point. Example below...
<div id="2"></div>
<div id="1"></div>
<div id="3"></div>
如果是这种情况,是否可以获取我单击的最后一个div ID?
So if this is the case, is there a way to get the last div ID I clicked?
推荐答案
您是这个意思吗?
var lastID;
// document.ready
$(function() {
$("div").on("click", function() {
lastID = $(this).attr("id");
});
});
function something() {
// lastID is the id of the last div clicked.
}
在document.ready函数外部声明lastID意味着它可以全局访问,因此您以后可以在其他函数中使用它.
Declaring lastID outside the document.ready function means it's globally accessible, so you can use it in other functions later.
这篇关于获取最后点击的ID-jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文