W3.JS HTML sluit in

Sluit 'n HTML-lêer in:

w3.includeHTML()

Die HTML

Stoor die HTML wat jy in 'n .html-lêer wil insluit:

inhoud.html

<a href="https://www.w3schools.com/html/">HTML</a><br>
<a href="https://www.w3schools.com/css/">CSS</a><br>
<a href="https://www.w3schools.com/bootstrap/">Bootstrap</a><br>
<a href="https://www.w3schools.com/js/">JavaScript</a><br>
<a href="https://www.w3schools.com/sql/">SQL</a><br>
<a href="https://www.w3schools.com/php/">PHP</a><br>
<a href="https://www.w3schools.com/w3css/">W3.CSS</a><br>

Sluit die HTML in

HTML insluit word gedoen deur 'n w3-include-html- kenmerk te gebruik:

Voorbeeld

<div w3-include-html="content.html"></div>

Voeg die JavaScript by

HTML insluit word deur JavaScript gedoen.

Maak seker jou bladsy het w3.js gelaai en bel w3.includeHTML() :

Voorbeeld

<script>
w3.includeHTML();
</script>

Volledige voorbeeld

Voorbeeld

<!DOCTYPE html>
<html>
<script src="/lib/w3.js"></script>
<body>

<div w3-include-html="content.html"></div>

<script>
w3.includeHTML();
</script>

</body>
</html>

Sluit baie HTML-brokkies in

Jy kan enige aantal HTML-brokkies insluit:

Voorbeeld

<!DOCTYPE html>
<html>
<script src="/lib/w3.js"></script>
<body>

<div w3-include-HTML="h1.html"></div>
<div w3-include-HTML="content.html"></div>

<script>
w3.includeHTML();
</script>

</body>
<html>


Voeg 'n terugbelfunksie by

Wanneer jy HTML-brokkies in 'n webblad insluit, moet jy verseker dat ander funksies wat afhang van die ingeslote HTML nie uitgevoer word voordat die HTML behoorlik ingesluit is nie.

Die maklikste manier om kode te "terughou" is om dit in 'n terugbelfunksie te plaas.

'n Terugbelfunksie kan as 'n argument by w3.includeHTML():

Voorbeeld

<script>
w3.includeHTML(myCallback);

function myCallback() {
  // code that has to wait goes here
}
</script>

Jy sal 'n terugbelvoorbeeld in die volgende hoofstuk van hierdie tutoriaal vind.