Home > Web Front-end > JS Tutorial > Detailed explanation of the usage of JavaScript in XHTML_Basic knowledge

Detailed explanation of the usage of JavaScript in XHTML_Basic knowledge

WBOY
Release: 2016-05-16 17:37:19
Original
1137 people have browsed it

The rules for writing XHTML code are much stricter than writing HTML. Code like the following is valid in HTML, but invalid in XHTML.
[javascript]

Copy code The code is as follows:




In HTML, there are special rules to determine what content in the <script> element can be parsed, but these rules do not apply in XHTML. Because the less than sign (<) will be parsed as starting a new tag in XHTML. However, as a label, the less than sign cannot be followed by a space, thus causing a syntax error. <br>There are two solutions: first, replace all less than signs (<) in the code with the corresponding HTML entities (<); second, use a CData fragment to contain the JavaScript code. <br>Corresponding code for method one: <br>[javascript] <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="41685" class="copybut" id="copybut41685" onclick="doCopy('code41685')"><u>Copy code </u></a></span> The code is as follows: </div> <div class="codebody" id="code41685"> <br><script type="text/javascript"> <br>function compare(a, b) <br>{ <br>if(a < b) <BR>{ <BR>alert("a is less then b"); <BR>} <BR>else if(a > b) <br>{ <br>alert("a is greater then b"); <br>} <br>else <br> { <br>alert("a is equal to b"); <br>} <br>} <br></script>


Corresponding code for method two:
[javascript]
Copy code The code is as follows:



Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template