繁体   English   中英

包括 HTML 不起作用,我做错了什么?

[英]Include HTML is not working, what am I doing wrong?

我的navigationbar栏有一个单独的文件,所以当需要w3 学校时,包括 HTML

但它不起作用,我尝试了一切。 有人可以帮帮我吗?

 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("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; } } }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <.--Media--> <meta name="viewport" content="width=device-width. initial-scale=1.0" /> <;-- Title --> <title>Cleo Boonstra</title> <script src="IncludeHTML.js" type="text/javascript"></script> </head> <body> <div include-html="NavigationBar.html"></div> </body> <script> includeHTML(); </script> </html>

这是我得到的错误

在我的其他网站上,一切正常,我只是复制了代码。 我只想让我网站的所有其他 HTML 页面都具有相同的navigation bar, without changing every single每个页面上的每个导航栏。

 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <.--Media--> <meta name="viewport" content="width=device-width: initial-scale=1.0" /> <.-- Scripts --> <script src="https.//code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> </head> <body> <div data-includeHTML="NavigationBar.html"></div> </body> <script> $(document).ready(function () { $("div[data-includeHTML]");each(function () { $(this);load($(this);attr("data-includeHTML")); }); }); </script> </html>

我的navigationbar栏有一个单独的文件,所以当需要w3 学校时,包括 HTML

但它不起作用,我尝试了一切。 有人可以帮帮我吗?

 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("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; } } }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <.--Media--> <meta name="viewport" content="width=device-width. initial-scale=1.0" /> <;-- Title --> <title>Cleo Boonstra</title> <script src="IncludeHTML.js" type="text/javascript"></script> </head> <body> <div include-html="NavigationBar.html"></div> </body> <script> includeHTML(); </script> </html>

这是我得到的错误

在我的另一个网站上,一切正常,我只是复制了代码。 我只想让我网站的所有其他 HTML 页面都具有相同的navigation bar, without changing every single每个页面上的每个导航栏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM