ghhs("nav01","li"); // 鼠标经过时变色 ghhs("nav02","li","no"); // 只隔行换色 ghhs("nav03","li","onclick"); // 鼠标点击当前标记变色 隔行换色 - www.jb51.net 脚本之家 // 返回Id、Tag function Pid(id,tag){ if(!tag){return document.getElementById(id);} else{return document.getElementById(id).getElementsByTagName(tag);} } // 隔行换色 function ghhs(id,tag,s) { var line=Pid(id,tag); for (var i=1;i<line.length+1;i++) { line[i-1].className=(i%2>0)?"t1":"t2"; } if(s=="no"){ return; } else if(!s){ for(var i=0;i<line.length;i++) { line[i].onmouseover=function(){ this.tmpClass=this.className; this.className+=" up"; } line[i].onmouseout=function(){ this.className=this.tmpClass; } } } else{ for(var i=0;i<line.length;i++) { line[i].tmep=i; line[i][s]=function(){ ghhs_tab(this.tmep); } } } function ghhs_tab(s){ for(var i=0;i<line.length;i++){ if(!line[i].tmpClass){ line[i].tmpClass=line[i].className+=" pr1984_com"; } if(s==i){ line[i].className+=" up"; } else { line[i].className=line[i].tmpClass; } } } } .t1 {background:#eee;} .t2 {background:#fff;} .up {background:#ddd;} 路过 asdsad asdsad asdsad 无视路过 asdsad asdsad asdsad 踩我 asdsad asdsad asdsad ghhs("nav01","li"); ghhs("nav02","li","no"); ghhs("nav03","li","onclick"); [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]