【发布时间】:2020-05-16 07:29:36
【问题描述】:
当在我的网站上单击一个 div 时,我希望将另一个 html 文件的内容添加到现有的 html 中。我尝试了很多方法,但找不到解决方案。我不想使用 iframe 或 object 或 jquery 或 php。
function loadhtmlfile(filename, filetype, location){
var fileref=document.createElement('link');
fileref.setAttribute("rel", "html");
fileref.setAttribute("type","text/html");
fileref.setAttribute("href", filename);
document.getElementById("parentDiv").appendChild(fileref);
}
loadhtmlfile("my.html", "html", "parentDiv");
这会为 html 文件添加一个链接。它不会添加 html 文件的实际内容。
根据我的阅读,听起来最好使用服务器应用程序来执行此操作。我正在使用 node.js。如果最好做这个服务器端,我该如何使用 node.js?
我还将使用 websockets,所以我怀疑这会改变答案。
【问题讨论】: