100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > js加载事件(onload)

js加载事件(onload)

时间:2018-12-16 03:15:12

相关推荐

js加载事件(onload)

onload 事件会在页面或图像加载完成后立即发生,同时执行被调用的程序。

onload 通常用于<body>元素,在页面完全载入后(包括图片、css文件等等。)执行脚本代码。

使用方法:

在 HTML 中:

<body οnlοad="fun()"></body>

示例:

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title> 加载事件 </title><script type="text/javascript">function message(){alert("加载中,请稍等…"); }</script> </head><body onload ="message()">onload事件。</body></html>

在 JavaScript 中:

window.οnlοad=fun;

示例:

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title> 加载事件 </title><script type="text/javascript">window.οnlοad=message;function message(){alert("加载中,请稍等…"); }</script> </head><body>onload事件。</body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。