js 2个js发生冲突,下面2个js发生冲突 放在一个页面发生冲突,有时间现在就帮我解决一下 很急

2025-03-07 05:28:09
推荐回答(2个)
回答1:

var iTarget=0;
var g_timer=[];

function aa()
{
var oNav=document.getElementById('mag_nav');
var aH2=oNav.getElementsByTagName('h2');
var aUl=oNav.getElementsByTagName('ul');
var i=0;

for(i=0;i {
aUl[i].index=i;

aH2[i].onclick=function ()
{
var oUl=this.parentNode.getElementsByTagName('ul')[0];
var aLis=oUl.getElementsByTagName('li');

if(this.className == 'active')
{
hideMenu(oUl);
this.className='';
}
else
{
for(i=0;i {
hideMenu(aUl[i]);
aH2[i].className='';
}
showMenu(oUl);
this.className='active';
}
};
}
}

function hideMenu(oUl)
{
if(g_timer[oUl.index])
{
clearInterval(g_timer[oUl.index]);
}
g_timer[oUl.index]=setInterval("collesUl("+oUl.index+")", 30);
}

function showMenu(oUl)
{
var aLis=oUl.getElementsByTagName('li');

oUl.style.display='block';

iTarget=aLis[0].offsetHeight*aLis.length;

if(g_timer[oUl.index])
{
clearInterval(g_timer[oUl.index]);
}
g_timer[oUl.index] = setInterval("scaleUl("+oUl.index+")", 30);
}

function collesUl(index)
{
var oNav=document.getElementById('mag_nav');
var aUl=oNav.getElementsByTagName('ul');
var speed=Math.ceil((aUl[index].offsetHeight-0)/5);
var h=aUl[index].offsetHeight-speed;

if(h<=0)
{
aUl[index].style.height=0+'px';
aUl[index].style.display='none';
clearInterval(g_timer[index]);
g_timer[index]=null;
}
else
{
aUl[index].style.height=h+'px';
}
}

function scaleUl(index)
{
var oNav=document.getElementById('mag_nav');
var aUl=oNav.getElementsByTagName('ul');
var speed=Math.ceil((iTarget-aUl[index].offsetHeight)/5);
var h=aUl[index].offsetHeight+speed;

if(h >= iTarget)
{
aUl[index].style.height=iTarget+'px';

clearInterval(g_timer[index]);
g_timer[index]=null;
}
else
{
aUl[index].style.height=h+'px';
}
}

第2个js
function bb()
{
var oBtn3=document.getElementById('btn13');
var oBg3=document.getElementById('bg3');
var oAlert3=document.getElementById('alert3');
var oAlert4=document.getElementById('alert4');
var oBtn2=document.getElementById('altoo');
var oA=oAlert3.getElementsByTagName('a')[0];

oBtn3.onclick=function()
{
oBg3.style.display='block';
oAlert3.style.display='block';
};

oA.onclick=function()
{
oBg3.style.display='none';
oAlert3.style.display='none';
};

oBtn2.onclick=function()
{
oAlert3.style.display='none';
oAlert4.style.display='block';
};
oAlert4.getElementsByTagName('a')[0].onclick=function()
{
oBg3.style.display='none';
oAlert4.style.display='none';
};
};

window.onload=function(){
aa();
bb();
}

回答2:

两个onload,前一个会不执行是不是?使用下边这个绑定两个onload句柄,两个都可以执行了
if (window.addEventListener) {
window.addEventListener('load', handle, false);
} else if (window.attachEvent) {
window.attachEvent('onload', handle);
}