function menuFix() { var sfEls = document.getElementByIdfunction menuFix() {var sfEls = document.getElementById("menu").getElementsByTagName("li");for (var i=0; i0?" ":"") + "sfhover";}sfEls[i].onMouseDown=function() {this.className+=(this.className.

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 06:48:17
functionmenuFix(){varsfEls=document.getElementByIdfunctionmenuFix(){varsfEls=document.getElementById

function menuFix() { var sfEls = document.getElementByIdfunction menuFix() {var sfEls = document.getElementById("menu").getElementsByTagName("li");for (var i=0; i0?" ":"") + "sfhover";}sfEls[i].onMouseDown=function() {this.className+=(this.className.
function menuFix() { var sfEls = document.getElementById
function menuFix() {
var sfEls = document.getElementById("menu").getElementsByTagName("li");
for (var i=0; i0?" ":"") + "sfhover";
}
sfEls[i].onMouseDown=function() {
this.className+=(this.className.length>0?" ":"") + "sfhover";
}
sfEls[i].onMouseUp=function() {
this.className+=(this.className.length>0?" ":"") + "sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp("( |^)sfhover\\b"),
"");
}
}
}
window.onload=menuFix;

function menuFix() { var sfEls = document.getElementByIdfunction menuFix() {var sfEls = document.getElementById("menu").getElementsByTagName("li");for (var i=0; i0?" ":"") + "sfhover";}sfEls[i].onMouseDown=function() {this.className+=(this.className.
function menuFix() {//定义个函数
var sfEls = document.getElementById("menu").getElementsByTagName("li");//id为menu的(应该是ul标签)里的所有的子元素li标签的集合
for (var i=0; i0?" ":"") + "sfhover";//附加一个sfhover样式,如果原来没有样式,就是"sfhover",如果原来有个classname,比如是"style1",就变成"style1 sfhover"(格式所必须中间要有个空格的}
sfEls[i].onMouseDown=function() {//鼠标按住时
this.className+=(this.className.length>0?" ":"") + "sfhover";//同上}
sfEls[i].onMouseUp=function() {//鼠标放开时
this.className+=(this.className.length>0?" ":"") + "sfhover";//同上
}
sfEls[i].onmouseout=function() {//鼠标离开该LI标签时
this.className=this.className.replace(new RegExp("( |^)sfhover\\b"),""); //取消后面的"sfhover"样式,new RegExp("( |^)sfhover\\b个正则表达式,目的是把"sfhover"移除.也就是说还原成原来的样子
}
}
}
window.onload=menuFix;//页面加载时就执行这个规则