Here is the html code of my question
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset="UTF-8"></meta>
<title>Insert title here</title>
<script type="text/javascript">
var arr = [ "A", "B", "C" ];
for (var i = 0; i < arr.length; i++) {
document.write(arr[i]);;
}
</script>
</head>
<body>
</body>
</html>
In the line for (var i = 0; i < arr.length; i++)
it shows the error The content of elements must consist of well-formed character data or markup a.
between '<' and 'arr.length'
If I cancel the space between '<' and 'arr.length',then it shows another error Element type "arr.length" must be followed by either attribute specifications, ">" or "/>".
So consider that the code seems doesn't has any problems,then I try to change the "doctype" declaration of <<!DOCTYPE html>
And then everything goes well,now that I may can solve the problem with changing the doctype declaration.
But how can I do if the html file just must need the doctype declaration of <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
and I also don't want it to shows the unnecessary errors?
Thanks!
You need to add the <![CDATA]
here:
<script type="text/javascript">
//<![CDATA[
var arr = [ "A", "B", "C" ];
for (var i = 0; i < arr.length; i++) {
document.write(arr[i]);;
}
//]]>
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.