Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从另一个html页面创建html页面?_Html - Fatal编程技术网

如何从另一个html页面创建html页面?

如何从另一个html页面创建html页面?,html,Html,我想使用一个html页面,为所有其他html页面使用通用代码。我知道如何使用css,但我尝试过使用html,但失败了。我正在使用和不断更改的代码出现在所有其他页面上,因此不断浏览每一页来更改代码是很烦人的。如何执行此操作?您可以使用iframe拆分页面内容。例如,如果标题始终相同,则可以将其放置在iframe中,因此,如果修改它,chenges将影响所有页面但我认为这种方法已经过时了 您可以将html页面转换为php,并将静态代码拆分到另一个php文件中,以便在所有页面中都包含静态内容。您可以使

我想使用一个html页面,为所有其他html页面使用通用代码。我知道如何使用css,但我尝试过使用html,但失败了。我正在使用和不断更改的代码出现在所有其他页面上,因此不断浏览每一页来更改代码是很烦人的。如何执行此操作?

您可以使用
iframe
拆分页面内容。例如,如果标题始终相同,则可以将其放置在
iframe
中,因此,如果修改它,chenges将影响所有页面但我认为这种方法已经过时了


您可以将
html
页面转换为
php
,并将静态代码拆分到另一个
php
文件中,以便在所有页面中
都包含
静态内容。

您可以使用
iframe
拆分页面内容。例如,如果标题始终相同,则可以将其放置在
iframe
中,因此,如果修改它,chenges将影响所有页面但我认为这种方法已经过时了


您可以将
html
页面转换为
php
页面,并将静态代码拆分到另一个
php
文件中,以便在所有页面中
都包含
静态内容。

您可以使用此简单的html+js替代方案:

举个例子:

请参见示例:

    <!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>

函数includeHTML(){
var z,i,elmnt,file,xhttp;
/*循环浏览所有HTML元素的集合:*/
z=document.getElementsByTagName(“*”);
对于(i=0;i
您可以使用这个简单的html+js替代方案:

举个例子:

请参见示例:

    <!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>

函数includeHTML(){
var z,i,elmnt,file,xhttp;
/*循环浏览所有HTML元素的集合:*/
z=document.getElementsByTagName(“*”);
对于(i=0;i
我假设您刚刚开始。因此,以下是三个选项的高层次顺序,它们是最容易实现的(不一定是技术上最好的):

  • 使用。这些允许您将一个HTML页面加载到另一个页面中,这样您就可以拥有一个包含公共内容的外部页面,而不断变化的内容将进入iframe

  • 使用JavaScript,您可以拥有一个基本页面,然后使用JavaScript加载其他内容。一个非常简单的方法是使用jQuery库,它有一个函数,可以做您需要的事情

  • 在服务器上动态生成HTML。有很多不同的方法。最简单的是PHP


  • 我想你才刚刚开始。因此,以下是三个选项的高层次顺序,它们是最容易实现的(不一定是技术上最好的):

  • 使用。这些允许您将一个HTML页面加载到另一个页面中,这样您就可以拥有一个包含公共内容的外部页面,而不断变化的内容将进入iframe

  • 使用JavaScript,您可以拥有一个基本页面,然后使用JavaScript加载其他内容。一个非常简单的方法是使用jQuery库,它有一个函数,可以做您需要的事情

  • 在服务器上动态生成HTML。有很多不同的方法。最简单的是PHP


  • 这些HTML是静态的吗?是的,HTML文档是静态的static@Muskratis你需要使用一个模板系统,比如Twig或者HTML和PHP的组合(包含函数)来实现这一点。好的,谢谢你让我知道。我在任何地方都找不到html的任何内容,所以我现在将查找这些内容,如果它是您可以执行的唯一html,就像这里解释的那样:我并不是说它是一个好的解决方案!只是说它会起作用。如果您可以在服务器端呈现HTML,那么这将是使这些HTML保持静态的好方法?是的,HTML文档是静态的static@Muskratis你需要使用一个模板系统,比如Twig或者HTML和PHP的组合(包含函数)来实现这一点。好的,谢谢你让我知道。我在任何地方都找不到html的任何内容,所以我现在将查找这些内容,如果它是您可以执行的唯一html,就像这里解释的那样:我并不是说它是一个好的解决方案!只是说它会起作用。如果你能在服务器端呈现HTML,那将是一个很好的方法谢谢你这正是我要找的谢谢你这正是我要找的