jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
load(url, params, callback)
load(url, params, callback)

装入一个远程HTML内容到一个DOM结点。

注意:避免用装入的scripts脚本,装入脚本改用$.getScript.当任何字符显示时,IE会忽略所有的脚本。

返回值:jQuery

参数:

  • url (String): 装入的HTML文件url地址
  • params (Object): (可选)发送到服务端的键/值对参数。
  • callback (Function): (可选) 当数据装入完成时执行的函数.
 

示例:

$("#feeds").load("feeds.html");

HTML 代码:

<div id="feeds"></div>

结果:

<div id="feeds"><b>45</b> feeds found.</div>

示例:

和上面相似,但加入了当数据装入后执行一个回调函数参数。

$("#feeds").load("feeds.html",
  {limit: 25},
  function()   {
   alert("The last 25 entries in the feed have been loaded");
  } 
); 
 
load( url, params, callback )

Load HTML from a remote file and inject it into the DOM.

Note: Avoid using this to load scripts, instead use $.getScript. IE strips script tags when there aren't any other characters in front of it.

Return value: jQuery
Parameters:

  • url (String): The URL of the HTML file to load.
  • params (Object): (optional) A set of key/value pairs that will be sent as data to the server.
  • callback (Function): (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
 

Example:

 $("#feeds").load("feeds.html");  
Before:
 <div id="feeds"></div>  
Result:
 <div id="feeds"><b>45</b> feeds found.</div>

Example:

Same as above, but with an additional parameter and a callback that is executed when the data was loaded.

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