简体   繁体   English

W3C 验证器和 jquery

[英]W3C validator and jquery

I'm having a lot of errors when I run W3C validator on an html page with jquery code.当我使用 jquery 代码在 html 页面上运行 W3C 验证器时,我遇到了很多错误。 This is an example of the jquery code I'm using:这是我正在使用的 jquery 代码示例:

jQuery(document).ready(function($) 
{
    /*<![CDATA[*/

    $("body").append("<div id='mainBody'>");
    $("#mainBody").append("<h1 align='center'>SCORM Authoring Tools");

    $("#mainBody").append("<table id='myTable' border='1' />");

    $("#myTable").append("<tr id='tr1' />");
    /*]]>*/
});

This is an example of these errors:这是这些错误的一个示例:

Line 4, Column 267: end tag for element "TD" which is not open
append("<td class='rows'>Product</td>");    
$("#tr1").append("<td class='rows'>…

I'm using <.DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4;0//EN">;我正在使用<.DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4;0//EN">; Thanks谢谢

It isn't the code you pasted that's causing the issue.导致问题的不是您粘贴的代码。 It's the code you didn't paste.这是您没有粘贴的代码。 The code below validates for me, with warnings, on http://validator.w3.org/#validate_by_input :下面的代码在http://validator.w3.org/#validate_by_input上为我验证,并带有警告:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>JS Bin</title>
<script type="text/javascript">
jQuery(document).ready(function($) 
{
    /*<![CDATA[*/

    $("body").append("<div id='mainBody'>");
    $("#mainBody").append("<h1 align='center'>SCORM Authoring Tools");

    $("#mainBody").append("<table id='myTable' border='1' />");

    $("#myTable").append("<tr id='tr1' />");
    /*]]>*/
});
</script>
</head>
<body>
  <p id="hello">Hello World</p>
</body>
</html>

I think it's probably missing or incorrect <script> tags.我认为它可能缺少或不正确的<script>标签。

As Felix King pointed out, you can also remove the CDATA comments, since you're validating with HTML rather than XML.正如 Felix King 指出的那样,您也可以删除CDATA注释,因为您使用 HTML 而不是 XML 进行验证。

You'd want to put it around all your code:你想把它放在你所有的代码周围:

/*<![CDATA[*/
jQuery(document).ready(function($) 
{

    $("body").append("<div id='mainBody'>");
    $("#mainBody").append("<h1 align='center'>SCORM Authoring Tools");

    $("#mainBody").append("<table id='myTable' border='1' />");

    $("#myTable").append("<tr id='tr1' />");
});
/*]]>*/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM