window.onload = rolloverInit;
function rolloverInit() {
for (var i=0; i<document.links.length; i++)
var linkObj = document.links[i];
if (linkObj.className) {
var imgObj = document.getElementById(linkObj.className);
if (imgObj) {
setupRollover(linkObj,imgObj);
}
}
}
}
function setupRollover(thisLink,textImage) {
thisLink.imgToChange = new Array;
thisLink.outImage = new Array;
thisLink.overImage = new Array;
thisLink.imgToChange[0] = textImage;
thisLink.onmouseout = rollOut;
thisLink.onmouseover = rollOver;
thisLink.outImage[0] = new Image();
thisLink.outImage[0].src = textImage.src;
thisLink.overImage[0] = new Image();
thisLink.overImage[0].src = "images/" + thisLink.id + "Text.gif";
var rolloverObj = document.getElementById(thisLink.id + "Img");
if (rolloverObj) {
thisLink.imgToChange[1] = rolloverObj;
thisLink.outImage[1] = new Image();
thisLink.outImage[1].src = rolloverObj.src;
thisLink.overImage[1] = new Image();
thisLink.overImage[1].src = "images/" + thisLink.id + "_on.gif";
}
}
function rollOver() {
for (var i=0;i<this.imgToChange.length; i++) {
this.imgToChange[i].src = this.overImage[i].src;
}
}
function rollOut() {
for (var i=0;i<this.imgToChange.length; i++) {
this.imgToChange[i].src = this.outImage[i].src;
}
}
window.onload = rotate;
var thisAd = 0;
function rotate() {
var adImages = new Array("a38.png","a37.jpg","a36.png");
thisAd++;
if (thisAd == adImages.length) {
thisAd = 0;
}
document.getElementById("adBanner").src = adImages[thisAd];
setTimeout(rotate, 2 * 1000);
}
window.onload = initAll;
function initAll(){
document.getElementById("过去").onclick=saysomething;
document.getElementById("现在").onclick=saysomething;
document.getElementById("未来").onclick=saysomething;
}
function saysomething(){
switch(this.id){
case "过去":
alert("过去就是一首诗,思念的美");
break;
case "现在":
alert("现在就是一曲歌,旋律的荡漾");
break;
case "未来":
alert("未来就是一道桥,神秘且向往");
break;
default:
}
}
将js函数写在里面,想加几个就加几个。
直接不是回过你了,要用attachEvent或者addEventListener,不能直接window.onload=xxxx来添加事件
http://ask.csdn.net/questions/187584
function addEvent(o,evt,func){
if(o.attachEvent)o.attachEvent('on'+evt,func);
else if(o.addEventListener)o.addEventListener(evt,func,false);
}
//window.onload = rolloverInit;
addEvent(window,'load',rolloverInit)
//window.onload = initAll;
addEvent(window,'load',initAll)
//window.onload = rotate;
addEvent(window,'load',rotate)
不明白你在说什么,不知道你的要求是什么
你说加入一个页面加入3个js,直接引入不就行了。
没太明白你要问什么,你的意识是,调用几个js函数吗,写在方法里面,就可以吗
到加在几个写几个加载语句不就行了么,没明白你要问的~
给你一个缓存加载队列的函数
function addLoadEvent(func){
var oldonload = window.onload;
if(typeof window.onload != 'function'){
window.onload = func ;
}else{
window.onload = function(){
func();
oldonload();
}
}
}
然后直接addloadEvent(要执行的函数名);