和 <!DOCTYPE html>-6ren"> 和 <!DOCTYPE html>-这是我的问题的 html 代码 Insert title here var arr = [ "A", "B", "C" ]; for (var i = 0; i 在-6ren">
gpt4 book ai didi

javascript - Eclipse 中的 <!DOCTYPE html PUBLIC"....."> 和 <!DOCTYPE html>

转载 作者:行者123 更新时间:2023-12-03 05:20:24 29 4
gpt4 key购买 nike

这是我的问题的 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.在 '<' 和 'arr.length' 之间
如果我取消 '<' 和 'arr.length' 之间的空格,则会显示另一个错误 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 中的 &lt;!DOCTYPE html PUBLIC"....."> 和 &lt;!DOCTYPE html>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41413244/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com