[html] Javascript warning and error of w3c

There are some javascript in below of the page:

 

<script type="javascript">
var test = 4;
if(test < 5)
{
alert(
"Test w3c");
}
</script>

When test the page in http://validator.w3.org/#validate_by_uri, we got the warning and error:

 

 

Line X, ColumnX: XML paring Error: StartTag: invalid element name
if(test
< 5)

Why?

 

 

We can get the reason here: http://www.w3.org/TR/2002/REC-xhtml1-20020801/#h-4.8

The resolved:

 

<script type="javascript">
/*<![CDATA[*/
var test = 4;
if(test < 5)
{
alert(
"Test w3c");
}
/*]]
>*/
</script>

 

Add the "<![CDATA[" and "]]>" to the code!

 

posted @ 2010-05-20 16:11  DavidHHuan  阅读(422)  评论(0编辑  收藏  举报