Table of Contents
jQuery The functions of HTML() and Load() are very similar. They can both change the content of HTML. Of course, there are some obvious differences. " >jQuery The functions of HTML() and Load() are very similar. They can both change the content of HTML. Of course, there are some obvious differences.
The HTML() method changes the HTML content
Syntax
Example
Definition and usage
Navigation

1)主页面



<html>

<head>

<title></title>

<script src="js/jquery-1.4.4.min.js" type="text/
javascript"></script>

<script type="text/javascript">

   $(document).ready(
function() {

       $(
"#target").load("target.html", function() {


       });

   });

</script>

</head>

<body>

<p id="target"></p>

</body>

</html>

2) 子页面



<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>

<script type="text/javascript">

   alert(
"hello world!I am target");

</script>

above is script

Copy after login
" >

1)主页面



<html>

<head>

<title></title>

<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>

<script type="text/javascript">

   $(document).ready(
function() {

       $(
"#target").load("target.html", function() {


       });

   });

</script>

</head>

<body>

<p id="target"></p>

</body>

</html>

2) 子页面



<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>

<script type="text/javascript">

   alert(
"hello world!I am target");

</script>

above is script

Copy after login
Home Web Front-end JS Tutorial The difference between jQuery's HTML() and Load()

The difference between jQuery's HTML() and Load()

May 15, 2018 pm 04:51 PM
html jquery load

jQuery The functions of HTML() and Load() are very similar. They can both change the content of HTML. Of course, there are some obvious differences.

jQuery HTML Operation details:

jQuery contains many powerful functions for changing and manipulating HTML.

The HTML() method changes the HTML content

Syntax

$(selector).html(content)
Copy after login

Similar to the html() function, it changes the content of the matched HTML element (innerHTML) .

Example

$("p").html("html content");

jQuery Load Operation details:

Definition and usage

The load() method loads the remote HTML file code and inserts it into the DOM.

The difference between Jquery's Load() method and html() is that after loading the remote HTML file, it can also execute the Javascrpt script in it.

The GET method is used by default - automatically converted to POST method when passing additional parameters.

In jQuery 1.2, you can specify a selector to filter the loaded HTML document, and only the filtered HTML code will be inserted into the DOM. The syntax is like "url #some > selector".

Please see the example below.

Syntax

load(url,[data],[callback])
Copy after login
##dataThe key/ sent to the server. value data. In jQuery 1.3, a ##callback. Example 1
Parameters Description
url The URL of the HTML page to be loaded
string can also be accepted.
Callback executed when loading is successful. Function
Similar to the above example, but sends additional parameters as a POST and displays the message on success:

$("#feeds").load("feeds.php", {limit: 25}, function(){
  alert("The last 25 entries in the feed have been loaded");
});
Copy after login

Example 2

Load article sidebar section to an unordered list:

HTML code:

&lt;b&gt;jQuery Links:&lt;/b&gt;
&lt;ul id=&quot;links&quot;&gt;&lt;/ul&gt;
Copy after login
jQuery code :

$("#links").load("/Main_Page #p-Getting-Started li");
Copy after login

Example 3

<p><span style="color: #000000;">1)主页面<br><br><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">html</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">head</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">title</span><span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">title</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">script </span><span style="color: #ff0000;">src</span><span style="color: #0000ff;">=&quot;js/jquery-1.4.4.min.js&quot;</span><span style="color: #ff0000;"> type</span><span style="color: #0000ff;">=&quot;text/<a href="http://www.php.cn/wiki/48.html" target="_blank">javascript</a>&quot;</span><span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">script</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">script </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">=&quot;text/javascript&quot;</span><span style="color: #0000ff;">&gt;</span><span style="background-color: #f5f5f5; color: #000000;"><br><br>    $(<a href="http://www.php.cn/code/658.html" target="_blank">document</a>).ready(</span><span style="background-color: #f5f5f5; color: #0000ff;">function</span><span style="background-color: #f5f5f5; color: #000000;">() {<br><br>        $(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">#target</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">).load(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">target.html</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #0000ff;">function</span><span style="background-color: #f5f5f5; color: #000000;">() {<br><br><br>        });<br><br>    });<br><br></span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">script</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">head</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">body</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">p </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">=&quot;target&quot;</span><span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">p</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">body</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">html</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br>2) 子页面<br><br><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">script </span><span style="color: #ff0000;">src</span><span style="color: #0000ff;">=&quot;js/jquery-1.4.4.min.js&quot;</span><span style="color: #ff0000;"> type</span><span style="color: #0000ff;">=&quot;text/javascript&quot;</span><span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">script</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">script </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">=&quot;text/javascript&quot;</span><span style="color: #0000ff;">&gt;</span><span style="background-color: #f5f5f5; color: #000000;"><br><br>    alert(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">hello world!I am target</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br><br></span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">script</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br><br>above is script</span></p>
Copy after login

The above is the detailed content of The difference between jQuery's HTML() and Load(). For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

Nested Table in HTML

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Table Border in HTML

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

HTML margin-left

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

HTML Table Layout

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Moving Text in HTML

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

HTML Ordered List

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

HTML onclick Button

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

How do you parse and process HTML/XML in PHP?

See all articles