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

用GET方式装入并执行一个远程JavaScript文件。

注意:Safari在2.0.x或以下版本脚本不能全局内容同步,如果你通过getScript装入一个函数,请确信延迟正确装入后调用。

返回值:XMLHttpRequest

参数:

  • url (String): 装入页面的URL地址
  • callback (Function): (可选) 当数据装入完成时执行的函数.
 

示例:

$.getScript("test.js");

示例:

$.getScript("test.js",
   function(){
     alert("Script loaded   and executed.");
   }
); 
 
$.getScript( url, callback )

Loads, and executes, a remote JavaScript file using an HTTP GET request.

Warning: Safari <= 2.0.x is unable to evaluate scripts in a global context synchronously. If you load functions via getScript, make sure to call them after a delay.

Return value: XMLHttpRequest
Parameters:

  • url (String): The URL of the page to load.
  • callback (Function): (optional) A function to be executed whenever the data is loaded successfully.
 

Example:

 $.getScript("test.js");  

Example:

 $.getScript("test.js",
   function(){
     alert("Script loaded and executed.");
   }
 );