Как сделать - вставить HTML в HTML
Узнайте, как включить фрагменты HTML в HTML.
HTML
Сохраните HTML-код, который требуется включить в файл. HTML:
content.html
<a href="howto_google_maps.php">Google Maps</a><br>
<a href="howto_css_animate_buttons.php">Animated Buttons</a><br>
<a href="howto_css_modals.php">Modal Boxes</a><br>
<a href="howto_js_animate.php">Animations</a><br>
<a href="howto_js_progressbar.php">Progress Bars</a><br>
<a href="howto_css_dropdown.php">Hover Dropdowns</a><br>
<a href="howto_js_dropdown.php">Click Dropdowns</a><br>
<a href="howto_css_table_responsive.php">Responsive Tables</a><br>
Включите HTML
В том числе HTML делается с помощью W3-include-HTML атрибут:
Пример
<div w3-include-html="content.html"></div>
Добавить JavaScript
HTML включает в себя делается JavaScript.
Пример
<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>
Вызовите includeHTML() в нижней части страницы:
Пример
<script>
includeHTML();
</script>
Включить много фрагментов HTML
Можно включить любое количество фрагментов HTML:
Пример
<div w3-include-html="h1.html"></div>
<div
w3-include-html="content.html"></div>