這裏是代碼
$(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