像这个例子,鼠标悬停在其它导航上, 这个类就添加到悬停的导航上,然后移除首页的类。鼠标离开时类就回到首页,谢谢!请问怎么做?
4 回答
柠檬酸钠
TA贡献331条经验 获得超534个赞
var nav = document.getElementById('topNav'); var lis = nav.getElementsByTagName('li'); var current; for (var i=0;i<lis.length;i++) { if ((/\b(current)\b/).test(lis.className)) { current = lis[i]; break; } } for (var i=0;i<lis.length;i++) { lis[i].mouseenter = function () { current.className = ''; current = this; this.className = 'current'; } }
怎么感觉有点小错误,你先试一下吧
nickylau82
TA贡献128条经验 获得超67个赞
var load = function(){ var lis = document.getElementsByTagName("li"), i=0, liLength = lis.length, current; for(;i<liLength;i++){ (function(k){ lis[i].onclick = function(){ if(current){ current.className = ""; } this.className = "current"; current = this; }; })(i); } };
php_go
TA贡献16条经验 获得超24个赞
$("li").mouseover(function(){ $(this).addClass("current"); }).mouseout(function(){ $(this).removeClass("current"); })
添加回答
举报
0/150
提交
取消