这是我的问题的HTML代码
<!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>
在
for (var i = 0; i < arr.length; i++)
行中,它显示了'The content of elements must consist of well-formed character data or markup a.如果取消“ Element type "arr.length" must be followed by either attribute specifications, ">" or "/>".
因此,考虑代码似乎没有任何问题,然后尝试更改
<<!DOCTYPE html>
的“ doctype”声明然后一切顺利,现在我可以通过更改doctype声明解决问题。
但是,如果html文件只需要
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
的doctype声明,又不想显示不必要的错误,该怎么办?谢谢!
最佳答案
您需要在此处添加<![CDATA]
:
<script type="text/javascript">
//<![CDATA[
var arr = [ "A", "B", "C" ];
for (var i = 0; i < arr.length; i++) {
document.write(arr[i]);;
}
//]]>
</script>
关于javascript - Eclipse中的<!DOCTYPE html PUBLIC“…”>和<!DOCTYPE html>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41413244/