我有一个函数,当用户单击链接时会触发该函数。当他们单击另一个链接时,我想更改他们单击的第一个链接。我该怎么做呢?这是我到目前为止所拥有的:
$('a').click(function(){
//some code ...
if ( $(this).attr('id') != last.attr('id') ) {
$('a').click(function()
/*the original $this*/.parent().parent().quickFlipper({refresh: 0});
/*the original last*/.parent().parent().quickFlipper({refresh: 0});
});
var that = this;
var that2 = last;
setTimeout(function(){
$(that).parent().parent().quickFlipper({refresh :0});
$(that2).parent().parent().quickFlipper({refresh :0});
}, 1500);
//some more code ...
});
提前致谢,如果您不确定我要实现的目标,请提出任何问题。
最佳答案
这是使用闭包的好时机。
$('a').click((function () {
//private
var lastClicked;
return function () {
//your code
if(lastClicked) {
//do something to the last clicked element
}
lastClicked = this;
};
})());
关于javascript - 如何定位之前的 $(this)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11617060/