活动伪类不起作用

当我点击链接“家”类家应该改变并留在class级home1直到另一个链接被点击但它没有…类更改但点击其他链接“再见”“家”的类没有从home1更改回home,它也不再可点击。

php是

TEST    $("ul.nav li").click(function(e) { var newclass=($(this).attr("class")+"1"); var oldclass=($(this).attr("class")); alert($(this).attr("class")+"1"); $(this).attr( "class",newclass); });       

CSS

 body { width:1020px; margin:0 auto; position:absolute; } .sidebar { margin-left:10px; } .nav { display:block; margin-top:60px; } ul { list-style-type:none; } a{ text-decoration:none; border:none; } li.home{ background: $666 no-repeat; width:150px; height:65px; color:#fff; } li.bye{ background: $666 no-repeat; width:150px; height:65px; color:#fff; } li.home:hover { background: #678fef no-repeat; color:#fff; } li.bye:hover { background: #678fef no-repeat; color:#fff; } li.home1 { background: #678fef no-repeat; color:#fff; } li.bye1 { background: #678fef no-repeat; color:#fff; } 

我已经在代码中添加了jquery,但仍然没有警告框或所需的结果plz指出我的错误

你可以看到它

请帮助

:只有在按住链接上的鼠标按钮时,才会激活活动状态! 在您单击其他链接之前它不会处于活动状态! 这可以用jQuery完成:

 $('a').click(function() { $('a.lastClickedLink').removeClass('lastClickedLink'); $(this).addClass('.lastClickedLink'); }); 

最后点击的链接将具有lastClickedLink类,然后可以通过带有a.lastClickedLink {} css进行样式设置。

如果您希望此类在用户稍后返回页面时保持持久性,则必须使用cookie。 为此使用jQuery cookie 。

你想要实现这个目标吗?

         

或者只是在这个小提琴上测试它http://jsfiddle.net/FHsvj/

干杯!