我正在嘗試使用以下代碼嘗試從設置的目錄中獲取圖像,並將其預加載。我不想將圖像加載到一個div,而是使用普通預加載到存儲器:如何使用jquery從目錄加載圖像
new Image().src = "/wp-content/themes/NCHERM_Theme/images/home4-events.jpg";
我是相當新的jQuery的所以尋找一些幫助來完成這一點:
window.onload = function($) {
var folder = "images/preload";
$.ajax({
url : folder,
success: function (data) {
//go through each item in folder
$.each(data, function(i,filename) {
//take each item and run into the normal preload method
setTimeout(function() {
// preload images
new Image().src = filename;
}, 1000);
});
}
});
};
運行這個在WordPress我得到`403上的URL forbbiden」文件夾之前,我甚至可以測試,如果這是工作
好像你重寫了$對象。將它從參數 –
代替'$'刪除它嘗試jQuery,對象,$,ajax到jQuery.ajax({ – LogicBlower
修復,幫助解決即時錯誤,但現在得到403禁止在文件夾url – HollerTrain