如何向元素添加onload事件?我可以用吗:
<div onload="oQuickReply.swap();" ></div>
Run Code Online (Sandbox Code Playgroud)
为了这?
我有几个背景图像的div.我想知道如何使用gif图像预加载那些背景图像,因为一些背景图像非常大.执行以下操作不起作用:
HTML:
<div id="glykopeels" onload="loadImage()">Glykopeels Content</div>
<div id="facials" onload="loadImage2()">Facials Content</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#glykopeels{
background: #ebebeb url(http://lamininbeauty.co.za/images/products/preloader.gif) no-repeat top right;
background-size: contain;
}
#facials{
background: #ebebeb url(http://lamininbeauty.co.za/images/products/preloader.gif) no-repeat top right;
background-size: contain;
}
Run Code Online (Sandbox Code Playgroud)
JS:
function loadImage(){
document.getElementById('glykopeels').style.background = '#ebebeb url(http://lamininbeauty.co.za/images/products/glykopeel.jpg);';
}
function loadImage2(){
document.getElementById('facials').style.background = '#ebebeb url(http://lamininbeauty.co.za/images/products/facial.jpg);';
}
Run Code Online (Sandbox Code Playgroud)
我想在onload函数中为该元素定义一个不同的ID,并为该新ID定义css是另一种可能性吗?这样只更改onload函数中该元素的id?
谢谢