只能通过原生js,并且需要使用 fetch 故请注意 当前浏览器是否支持 fetch ```js fetch('/static/') .then(function(response) { return response.text() }) .then(function(body) { const parser = new DOMParser() const htmlDoc = parser.parseFromString(body, 'text/html') // 将 HTML 字符串转换为文档对象模型 const links = Array.from(htmlDoc.getElementsByTagName('a')) // 获取页面上所有链接元素 // 过滤出位于 /static/ 目录下的链接 const staticLinks = links.filter(function(link) { return link.getAttribute('href').startsWith('\\static\\') }) const fileList = staticLinks.map(function(link) { return link.textContent // 返回链接元素的文本内容,也就是文件名 }) console.log(fileList) // 打印文件列表 }) ``` 最后修改:2023 年 05 月 04 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏