每当尝试在Chrome中打开时,我都会因为HTTPS错误而收到错误,Chrome会阻止安全性。
function w3IncludeHTML() { var z, i, a, file, xhttp; z =
document.getElementsByTagName("*"); for (i = 0; i < z.length; i++)
{
if (z[i].getAttribute("w3-include-html")) {
a = z[i].cloneNode(false);
file = z[i].getAttribute("w3-include-html");
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
a.removeAttribute("w3-include-html");
a.innerHTML = xhttp.responseText;
z[i].parentNode.replaceChild(a, z[i]);
w3IncludeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
return;
}
}
}
答案 0 :(得分:0)
我知道它的第三方库,但这个库怎么样:
https://github.com/darshanmarathe/partialjs
它本质上是来自Angular的ng-include的翻版,但是独立且仅约2kb缩小。允许您完全按照您的要求行事:
<partial src="templates/header.html"></partial>`