我想对所有其他html页面使用具有通用代码的html页面。我知道如何使用CSS,但是我尝试使用html失败。我正在使用并不断更改的代码出现在所有其他页面上,因此不断浏览每个页面进行更改很烦人。我该怎么办?
答案 0 :(得分:0)
您可以使用most_common
拆分页面内容。例如,如果标头始终相同,则可以将其放置在for i, common in enumerate(scores.most_common(5), 1):
print(i, common[0] + " -", common[1])
中,因此,如果您对其进行修改,则将影响所有页面。 但是我认为这种方法已经过时了。
您可以将iframe
页转换为iframe
,然后将静态代码拆分到另一个html
文件中,以便可以在所有页面中php
静态内容。 / p>
答案 1 :(得分:0)
您可以使用这种普通的html + js替代方法:https://www.w3schools.com/howto/howto_html_include.asp
,例如:https://www.w3schools.com/howto/tryit.asp?filename=tryhow_html_include_2
请参见示例:
<!DOCTYPE html>
<html>
<script>
function includeHTML() {
var z, i, elmnt, file, xhttp;
/*loop through a collection of all HTML elements:*/
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("w3-include-html");
if (file) {
/*make an HTTP request using the attribute value as the file name:*/
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {elmnt.innerHTML = this.responseText;}
if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
/*remove the attribute, and call this function once more:*/
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/*exit the function:*/
return;
}
}
};
</script>
<body>
<div w3-include-html="h1.html"></div>
<div w3-include-html="content.html"></div>
<script>
includeHTML();
</script>
</body>
</html>
答案 2 :(得分:0)