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

What is the usage of load in JavaScript?

醉折花枝作酒筹
Release: 2023-01-07 11:44:14
Original
11485 people have browsed it

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)
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template