Home  >  Article  >  Web Front-end  >  What is the usage of load in JavaScript?

What is the usage of load in JavaScript?

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-19 16:21:2111371browse

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).

What is the usage of load in JavaScript?

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)

What is the usage of load in JavaScript?

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:

What is the usage of load in JavaScript?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn