jQuery.getScript(url, [callback])
标签:
jQuery.getScript(url, [callback]) 概述
通过 HTTP GET 请求载入并执行一个 JavaScript 文件。大理石平台精度等级
jQuery 1.2 版本之前,getScript 只能调用同域 JS 文件。 1.2中,,您可以跨域调用 JavaScript 文件。注意:Safari 2 或更早的版本不能在全局作用域中同步执行脚本。如果通过 getScript 加入脚本,请加入延时函数。
参数url,[callback]String,FunctionV1.0
url:待载入 JS 文件地址。
callback:成功载入后回调函数。
示例 描述:
载入 <a title="http://jquery.com/plugins/project/color" href="http://jquery.com/plugins/project/color">jQuery 官方颜色动画插件</a> 成功后绑定颜色变化动画。
HTML 代码: <button>» Run</button> <div></div> jQuery 代码: jQuery.getScript("http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js", function(){ $("#go").click(function(){ $(".block").animate( { backgroundColor: ‘pink‘ }, 1000) .animate( { backgroundColor: ‘blue‘ }, 1000); }); }); 描述:加载并执行 test.js。
jQuery 代码: $.getScript("test.js"); 描述:加载并执行 test.js ,成功后显示信息。
jQuery 代码: $.getScript("test.js", function(){ alert("Script loaded and executed."); });jQuery.getScript(url, [callback])
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/41364.html