javascript HTML1527:应为 DOCTYPE。最短的有效文档类型是“<!DOCTYPE html>”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26871413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML1527: DOCTYPE expected. The shortest valid doctype is "<!DOCTYPE html>"
提问by Panadol Chong
Good day,
再会,
I am working on a c# web application, everything is working until I add in a normal JavaScript.
我正在开发 ac# web 应用程序,一切正常,直到我添加了一个普通的 JavaScript。
The html code is something as follow:
html代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="scripts/JScript.js" type="text/javascript"></script>
<asp:ContentPlaceHolder id="headContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<asp:ContentPlaceHolder id="title" runat="server"></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder id="bodyContent" runat="server"></asp:ContentPlaceHolder>
<!-- some code here -->
</body>
The JScript.js
is the JavaScript that put in.
该JScript.js
是把在JavaScript。
The JavaScript code is something as follow:
JavaScript 代码如下:
function getCookie(catId) {
var ebRand = Math.random() + '';
ebRand = ebRand * 1000000;
document.write('<scr' + 'ipt src="HTTP://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=553971&rnd=' + ebRand + '"></scr' + 'ipt>');
}
This JavaScript function will be trigger when a link button is click.
当点击链接按钮时,将触发此 JavaScript 函数。
I hit error in IE but Chrome and Mozilla is working fine.
我在 IE 中遇到错误,但 Chrome 和 Mozilla 工作正常。
My error in IE console is
HTML1527: DOCTYPE expected. The shortest valid doctype is "<!DOCTYPE html>".
我在 IE 控制台中的错误是
HTML1527: DOCTYPE expected. The shortest valid doctype is "<!DOCTYPE html>".
After search in Google, I try to put in
在谷歌搜索后,我尝试输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
as new DOCTYPE
, but it not working also.
作为新的DOCTYPE
,但它也不起作用。
and I have try put
我已经试过了
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
inside <head></head>
里面 <head></head>
But I still get the same error in IE also.
但是我在 IE 中仍然遇到同样的错误。
Is is problem in ContentPlaceHolder
?
问题出在ContentPlaceHolder
?
Other than that, I have go to W3C Markup Validation Service to do some validation of the address :
除此之外,我还去了 W3C 标记验证服务对地址进行了一些验证:
And go to http://validator.w3.org/checkto put in <script src="HTTP://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=553971&rnd=20079.082210606393"></script>
as well.
并转到http://validator.w3.org/check进行输入<script src="HTTP://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=553971&rnd=20079.082210606393"></script>
。
But not understand what is the validation result means.
但不明白验证结果是什么意思。
Kindly advise.
好心提醒。
回答by Jukka K. Korpela
IE issues a warningabout <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
, because such a string is not a valid doctype according to HTML5. The warning as such has no impact on anything. It's just part of HTML5 evangelism.
IE发出关于的警告<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
,因为根据 HTML5,这样的字符串不是有效的文档类型。这样的警告对任何事情都没有影响。这只是 HTML5 传播的一部分。
After you changed it to <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
, the issue was removed. But you probably saw the results of using some cached copy that has a wrong doctype. Testing with a fresh file (with a new name) should fix this issue.
将其更改为 后<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
,问题已消除。但是您可能看到了使用某些具有错误文档类型的缓存副本的结果。使用新文件(具有新名称)进行测试应该可以解决此问题。
Of course, the code as such does not validate, since the ASP tags are taken literally and interpreted as body
content, but that's a different issue.
当然,这样的代码不会验证,因为 ASP 标签是按字面意思理解的并被解释为body
内容,但这是一个不同的问题。
The practical move is to use <!DOCTYPE html>
as suggested. If you wish to still validate against the XHTML 1.0 specification for example, you can do this using the validator's user interface to override the doctype.
实际操作是<!DOCTYPE html>
按照建议使用。例如,如果您仍希望根据 XHTML 1.0 规范进行验证,您可以使用验证器的用户界面覆盖文档类型来执行此操作。
But it's not a big issue; you can just as well simply ignore the warning. If you have some functionalerrors, they are caused by something else and should be asked separately, with sufficient data provided.
但这不是什么大问题;您也可以简单地忽略警告。如果您有一些功能错误,它们是由其他原因引起的,应该单独询问,并提供足够的数据。