我正在建立一个单页的网站。将外部html附加到另一个html中。 CSS加载HTML但外部脚本不加载?
<button>
<a class="cd-btn-services" href="technical-services.html" id="mylink" data-type="page-transition">click me</a>
</button>
var myLink = document.getElementById('mylink');
myLink.onclick = function(){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "Public/Scripts/filename.js.";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
}
答案 0 :(得分:0)
你的src中有错误:
script.src = "Public/Scripts/filename.js";
不
script.src = "Public/Scripts/filename.js.";
你的代码为我工作