这里是代码
$(function() {
$("input[type=button]").click(
function(evt) {
if(!window.sayHi) {
evt.target.disabled = "disabled";
$.getScript("hi.js", function() {
sayHi($("input[type=text").val());
evt.target.disabled = "";
});
}
else{
sayHi($("input[type=text").val());
}
});
});
如果我按钮反复点击,然后$ .getScript(会发生什么)将重复下载hi.js文件或仅第一次?
$ .getScript()检查客户端机器中是否存在js文件....如果不是那么它只下载?请讨论。谢谢
我得到了关于getScript()函数的详细信息。在这里我给代码,我卡住了几行。
jQuery.cachedScript = function(url, options) {
// allow user to set any option except for dataType, cache, and url
options = $.extend(options || {}, {
dataType: "script",
cache: true,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax(options);
};
// Usage
$.cachedScript("ajax/test.js").done(function(script, textStatus) {
console.log(textStatus);
});
1)cachedScript()函数需要两个参数,但只有一个在调用时发送....为什么?
2)从哪里完成()函数来到这里?
请解释一下上面两点
全部解释了她的http://api.jquery.com/jQuery.getScript/ – 2012-03-17 18:35:17
不要懒惰......阅读函数的文档。 – gdoron 2012-03-17 18:42:51