且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将文件夹中的多个html文件加载到div中

更新时间:2023-12-02 21:30:46

希望这是您想要的:

$.each([
    'civic.html',
    'durango.html',
    'mustang.html',
    'r8.html'
], function(i,a){
    $("#all_cars").load("../cars/" + a);
});

$.each将遍历数组.


如果希望自动获取目录中的所有文件并列出它们,并且Web服务器上装有PHP,请添加一个名为carindex.php的文件,并将其内容设置为:


If you wish to automatically get all files in the directory and list them, and you have PHP on your web server, add a file called carindex.php, set it's content to:
<?php

print json_encode(scandir('PATH/TO/cars/', 1));

?>

然后在客户端:

$.get('/carindex.php', function (a) {
    a.forEach(function (b) {
        $("#all_cars").load("../cars/" + b);
    });
});