w3-学校包含html n

时间:2019-07-13 00:52:28

标签: html include

我以前使用过W3的include HTML。实际上,我的代码昨天有效。...这就是为什么这令人发疯的原因,因为它现在不起作用!

我已经从他们的网站上重新安装了代码,但仍然无法正常工作。

   <!DOCTYPE html>
   <html lang="en" dir="ltr">

  <link rel="stylesheet" href="includes/css/framework.css">
  <link rel="stylesheet" href="includes/css/style.css">

  <head>
    <meta charset="utf-8">
    <title></title>
  </head>

  <body>
    <div include-html="landing.html"></div>

  </body>

  <script type="text/javascript" src="includes/javascript/include.js">      </script>
   </html>

然后我们有了JS文件。

window.onload = function() {
    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("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("include-html");
            includeHTML();
          }
        }
        xhttp.open("GET", file, true);
        xhttp.send();
        /* Exit the function: */
        return;
      }
    }
  }

我希望我的“ landing.html”页面能够像昨天一样显示……但事实并非如此。

0 个答案:

没有答案