js當(dāng)中的onload事件
script標(biāo)簽內(nèi):
window.onload = function(){
? ? ? ? ? ? ? ? ??
? ? ?// 鼠標(biāo)移動(dòng)改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。
? ? ? ? ? var str_tr=document.getElementsByTagName('tr');
? ? ? ?for(var i=0;i<str_tr.length;i++){
? ? ? ? ? ?str_tr[i].setAttribute('onmouseover',document.all ? eval(function(){this.style.background="#f2f2f2"}) : 'javascript:this.style.background="#f2f2f2"');?
? ? ? ? ? ?str_tr[i].setAttribute('onmouseout',document.all?eval(function(){this.style.background="#fff"}):'javascript:this.style.background="#fff"');
? ? ? ?}
onload放的位置不一樣,起的作用也不一樣。那么上面onload放在script標(biāo)簽內(nèi)和放在<body ?onload="函數(shù)">,產(chǎn)生的效果有什么區(qū)別??
2016-04-30
都是等頁面加載完再執(zhí)行,區(qū)別不大