请问如何解决一个页面中两个onload问题 我在页面中include了导航栏页面,导航栏页面body中有一个onload,而我原页面也需要使用onload,这就导致只实现了导航栏中onload调用的js后一个onload无法工作,该如何解决?JavaScript 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 window.onload = function(){ alert(1)}if(window.onload){ var old = window.onload;}window.onload = function(){ if(typeof old === 'function') old(); alert(2)}或者用addEventListener(FF)跟attachEvent(IE)if(window.addEventListener){window.addEventListener('load',function(){ alert(1)},false)window.addEventListener('load',function(){ alert(2)},false);}else{window.attachEvent('onload',function(){ alert(1)})window.attachEvent('onload',function(){ alert(2)});} addEventListener('load',function,false)ieattachEvent('onload',function) dom下的那个事件绑定,可以多次绑定同一个事件。function addEvent(node,type,listener) { //使用前面的方法检查兼容性以保证平稳退化 if(node.addEventListener){ //W3C方法--FF node.addEventListener(type,listener,false); return true; }else if(node.attachEvent) { //MSIE方法--IE node['e'+type+listener] = listener; node[type+listener] = function(){ node['e'+type+listener](window.event); } node.attachEvent('on'+type,node[type+listener]); return true; } return false;}调用方法。node是你需要绑定的到的目标元素,第二个参数是事件,不需要加'on'前缀,第三个参数是事件处理函数addEvent(node,"click",func);试试看! 请问这样是还要写一个处理这个问题的js吗?还要写在html中? 谁能帮我改一个计时器! JS 循环选择 选择第一个和最后一个,中间连续被选. 载入的小窗口显示在前面 如何用JS实现:鼠标放在文字上,整行的背景色变色 时间日历控件怎么做的? 如何实现层的移动?急!!! Radior的length属性 nowrap如何使用? 请教!如何得到IE地址栏里的地址? 怎样使一个页面快速装载 新手学js,从哪里入手好啊? 在javascript中,如何往TD中写入javascript代码?
alert(1)
}
if(window.onload){
var old = window.onload;
}
window.onload = function(){
if(typeof old === 'function') old();
alert(2)
}
或者用addEventListener(FF)跟attachEvent(IE)
if(window.addEventListener){
window.addEventListener('load',function(){
alert(1)
},false)
window.addEventListener('load',function(){
alert(2)
},false);
}else{
window.attachEvent('onload',function(){
alert(1)
})
window.attachEvent('onload',function(){
alert(2)
});
}
ie
attachEvent('onload',function)
function addEvent(node,type,listener) {
//使用前面的方法检查兼容性以保证平稳退化
if(node.addEventListener){
//W3C方法--FF
node.addEventListener(type,listener,false);
return true;
}else if(node.attachEvent)
{
//MSIE方法--IE
node['e'+type+listener] = listener;
node[type+listener] = function(){
node['e'+type+listener](window.event);
}
node.attachEvent('on'+type,node[type+listener]);
return true;
}
return false;
}
调用方法。node是你需要绑定的到的目标元素,第二个参数是事件,不需要加'on'前缀,第三个参数是事件处理函数
addEvent(node,"click",func);试试看!