The usage of load in JavaScript is "$(element).load (function run when the specified element is loaded)". When the specified element (and sub-element) has been loaded, the load() event will occur. . This event applies to any element with a URL (such as images, scripts, frames, iframes).
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Definition and Usage
The load() event occurs when the specified element (and child elements) has been loaded.
This event applies to any element with a URL (such as images, scripts, frames, inline frames).
Depending on different browsers (Firefox and IE), the load event may not be triggered if the image has been cached.
$(selector).load(function)
When the image loads, change the text of the div element:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("img").load(function(){ $("div").text("图像已加载"); }); }); </script> </head> <body> <img src="/i/shanghai_lupu_bridge.jpg" / alt="What is the usage of load in JavaScript?" > <div>图像正在加载中 ...</div> <p><b>注释:</b>根据不同的浏览器(Firefox 和 IE),如果图像已被缓存,则也许不会触发 load 事件。</p> </body> </html>
Effect:
The above is the detailed content of What is the usage of load in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!