单击项目时菜单上的 jQuery removeClass
好吧,我有这个功能,当单击联系人时,它会向用户添加一个类,
$(".contactlink").live("click",function(e){
if(lastclicked == $(this).attr('href'))
{
return false;
}
contactinfo = lastclicked.split('/');
alert(lastclicked);
lastclicked = $(this).attr('href');
contactinfo = $(this).attr('href').split("/");
$("#friend_"+contactinfo[2]).addClass('active');
loadcontactinfo(contactinfo[2]);
//alert( contactinfo[2] );
return false;
});
所有工作正常,但这部分功能似乎没有将其自身保存到 jquery 中。
contactinfo = lastclicked.split('/');
alert(lastclicked);
因为当我执行“lastclicked”时,它不会提醒我上次单击的 href 链接是什么。
Ok so I have this function that when a contact is clicked it adds a class to the user
$(".contactlink").live("click",function(e){
if(lastclicked == $(this).attr('href'))
{
return false;
}
contactinfo = lastclicked.split('/');
alert(lastclicked);
lastclicked = $(this).attr('href');
contactinfo = $(this).attr('href').split("/");
$("#friend_"+contactinfo[2]).addClass('active');
loadcontactinfo(contactinfo[2]);
//alert( contactinfo[2] );
return false;
});
All is working fine, but this part of the function seems not to be saving it self to the jquery.
contactinfo = lastclicked.split('/');
alert(lastclicked);
cos when I do lastclicked it does not alert me what the href link which was click was last.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该确保在正确的范围内使用
var
声明变量。尝试类似的操作:有关简化的示例,请参阅 this jsfiddle
You should make sure that you are declaring variables with
var
in the proper scope. Try something like:For a simplified example see this jsfiddle
您是否在函数之前将 lastclicked 定义为 var ?
Did you define lastclicked as a var before your function?