开发者

valid html - '<' or '>' in between <script>tags

开发者 https://www.devze.com 2023-01-26 00:29 出处:网络
When I use the html validator: http://validator.w3.org/ It gives me an error. In the header of my page, I have something like this:

When I use the html validator:

http://validator.w3.org/

It gives me an error. In the header of my page, I have something like this:

<script type="text/javascript"> 
$(document).ready(function(){
    $('#countdown').countdown({
        until: '+2d+3h+1m+6s',
        layout: '{d<}{dn} {dl}, {d>}{hnn}:{mnn}:{snn}'
    });
});
</script>
开发者_如何学Go

The part within layout that is given a string contains a <. The validator is giving an error.

Do I just discount this, since it's part of a script tag? Is it something with the validator?

I know some might suggest putting it in an external file, but it's dynamic and I don't want to figure that out.


You wrap it with CDATA

<script type="text/javascript"> 
//<![CDATA[
$(document).ready(function(){
    $('#countdown').countdown({
        until: '+2d+3h+1m+6s',
        layout: '{d<}{dn} {dl}, {d>}{hnn}:{mnn}:{snn}'
    });
});
//]]>
</script>

Reference: https://developer.mozilla.org/en/properly_using_css_and_javascript_in_xhtml_documents


As mentioned in the HTML 4 Recommendation's note about specifying non-HTML data in element content, end tags are recognized within SCRIPT elements, but other kinds of markup --such as start tags and comments--are not. This is an unintuitive quirk of SGML for elements defined to have CDATA content.

Try

    <script type="text/javascript"> 
$(document).ready(function(){
    $('#countdown').countdown({
        until: '+2d+3h+1m+6s',
        layout: '{d<}{dn} {dl}, {d\>}{hnn}:{mnn}:{snn}'
    });
});
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消