我正在尝试使用以下代码尝试从设置的目录中获取图像,并将其预加载。我不想将图像加载到一个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