The full format of the Load method is: Load (URL, [data], [callback]),
which
URL: Refers to the address of the file to be imported.
data: Optional parameters; Because load can not only import static HTML files, but also import dynamic scripts, such as PHP files, so to import a dynamic file, we can put the parameters to pass here.
callback: optional parameter; is another function that is executed after the Load method is invoked and the server responds.
Directly on the code:
The code is as follows |
Copy Code |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" <title > New Document </title> <meta name= "generator" content= "EditPlus" <meta name= " Author "content=" " <meta name=" Keywords "content=" "" <meta name= "Description" Content= "" <body> <script src= "Jquery.js" ></SCRIPT> &NBSP;<SCRIPT> $ (document). Ready (function () { $ (' #but '). Click (function () { $ (' #test '). Load ("111.txt"); }); }); </script> <button id= "But" > change text </button> <div id= "test" >< H2> changes the text </body> |
Own local to have jquery.js and 111.txt text Document Oh, this text document should have content!
filter the loaded HTML document
After the URL Riga of the load, you can follow the selector.
For example:
The code is as follows |
Copy Code |
$ ("body"). Load ("test.html #a"); |
The last example is to load the contents of a test.html page into an element with an ID of "ResText". If you only need to load certain elements within the test.html page, you can use the URL parameters of the load () method to achieve the goal. By specifying a selector for the URL parameter, you can easily filter the content you want from the HTML document that is loaded.
The syntax structure of the URL parameter for the load () method is: "URL selector." Notice that there is a space between the URL and the selector.
For example, you only need to load content with class "Para" in the test.html page, which you can do using the following code:
The code is as follows |
Copy Code |
$ ("#resText"). Load ("test.html. para"); |
Delivery mode
The load () method is passed from the parameter data to a dynamic designation. If there is no parameter passing, the Get method is passed, and conversely, automatically converted to post.
The code is as follows |
Copy Code |
No parameter pass, then the Get method $ ("#resText"). Load ("test.php", function () { //...... }); With parameter passing, it is the Post method $ ("#resText"). Load ("test.php", {name: "xht555", Age: "},function" () { //...... }); |
How to use callback
For example, we can use the callback function when the load method gets the server response and slowly displays the loaded content. The code is as follows:
code is as follows |
copy code |
$ ("#go"). Click (function () { $ (#myID). Load ("welcome.php", {"lname": "Cai", "fname": "Adam", function () { & nbsp; $ ("#myID"). FadeIn (' slow ');} ); }); |