我在网页中引用了一个js文件,内容如下:function menuFix() {
var sfEls = document.getElementById("nav").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=(this.className.length>0? " ": "") + "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;
现在我加入了另一个功能,需要写入这样的代码: <script type="text/javascript">
window.addEvent('domready', function(){
var box = new multiBox('mb', {
overlay: new overlay()
}); var advanced = new multiBox('advanced', {
overlay: new overlay(),
descClassName: 'advancedDesc'
});
});
</script>
请问一下,如何将后面那个功能写入前面的函数menuFix里面才正确,各位朋友,有空的帮忙看看,谢谢!在线等
var sfEls = document.getElementById("nav").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=(this.className.length>0? " ": "") + "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;
现在我加入了另一个功能,需要写入这样的代码: <script type="text/javascript">
window.addEvent('domready', function(){
var box = new multiBox('mb', {
overlay: new overlay()
}); var advanced = new multiBox('advanced', {
overlay: new overlay(),
descClassName: 'advancedDesc'
});
});
</script>
请问一下,如何将后面那个功能写入前面的函数menuFix里面才正确,各位朋友,有空的帮忙看看,谢谢!在线等
window.onload=function(){
tmp();
window.addEvent('domready', function(){
var box = new multiBox('mb', {
overlay: new overlay()
}); var advanced = new multiBox('advanced', {
overlay: new overlay(),
descClassName: 'advancedDesc'
});
});
}要求你添加的功能要在menuFix函数所在js文件后加载。
中处理的时候,依赖于menuFix的执行结果。那就不行因为domready执行顺序早于window.onload你可以将上一个js中的:window.onload=menuFix;去除
然后在window.addEvent('domready', function(){
menuFix();
var box = new multiBox('mb', {
overlay: new overlay()
}); var advanced = new multiBox('advanced', {
overlay: new overlay(),
descClassName: 'advancedDesc'
});
});