admin管理员组文章数量:1307838
How i can determine the last clicked id ?! Because if i use :
if(clicks > 1){
var lc = event.target.id; // Last Clicked event
}
It will return the current button clicked id I have something like this :
$('#menu).click(function(event) {
clicks++;
if(clicks > 1){
var lc = event.target.id; // Last Clicked event
}
console.log(lc);
And i have 2 buttons Now if i click on first button console log will show undefinded but if i click on second button it will show his id.I want to prevent that
How i can determine the last clicked id ?! Because if i use :
if(clicks > 1){
var lc = event.target.id; // Last Clicked event
}
It will return the current button clicked id I have something like this :
$('#menu).click(function(event) {
clicks++;
if(clicks > 1){
var lc = event.target.id; // Last Clicked event
}
console.log(lc);
And i have 2 buttons Now if i click on first button console log will show undefinded but if i click on second button it will show his id.I want to prevent that
Share Improve this question edited May 12, 2012 at 10:52 Xtal asked May 12, 2012 at 10:44 XtalXtal 3051 gold badge6 silver badges21 bronze badges 2- Save it to a variable when the previous event happens. – kapa Commented May 12, 2012 at 10:46
- This is very little information, but usually what you are doing is saving the previous event since there is no history of events. – Amberlamps Commented May 12, 2012 at 10:47
2 Answers
Reset to default 5You can use .data()
for this,
<ul class="menu">
<li id="menu1">1</li>
<li id="menu2">2</li>
<li id="menu3">3</li>
<li id="menu4">4</li>
<li id="menu5">5</li>
</ul>
$(".menu li").click(function() {
if($(this).parent().data("lastClicked")){
alert($(this).parent().data("lastClicked"));
}
$(this).parent().data("lastClicked", this.id);
});
http://jsfiddle/aDUdq/
The variable lc
is local. You must write instead :
var lc;
if(clicks > 1){
lc = event.target.id; // Last Clicked event
}
console.log(lc);
本文标签: javascriptJquery last clickStack Overflow
版权声明:本文标题:javascript - Jquery last click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741818007a2399192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论