一般来说,只有
<body>,<img>, <link>, <script>,<frame>, <frameset>, <iframe>,
标签才有onload属性,其他标签是没有这个事件的。
下面总结一个广告弹框的方法,用onload+setTimeout
<style>
200px;
height:200px;
background-color: red;
position: fixed;
top: 0px;
right: 0px;
</style>
<script>
function init(){
var g=document.getElementById("guanggao");
g.style.display="none";
setTimeout(showGuanggao, 3000);
}
function showGuanggao(){
var g=document.getElementById("guanggao");
g.style.display="block";
};
function closeGuanggao(){
var g = document.getElementById("guanggao");
g.style.display ="none";
}
</script>
<body onload="init()">
<div id="guanggao">
<div id="guanggao">
<button onclick="closeGuanggao()">关闭</button>
</div>
</div>
</body>