简体   繁体   English

如何验证JavaScript?

[英]How do I validate a javascript?

I'm using a small snippet of JS to add a presentational element to my blockquotes ( As seen here ): 我正在使用一小段JS代码向我的代码块引用中添加一个表示性元素(如此处所示 ):

<script type="text/javascript"> 
    $('blockquote.message').append('<span class="arrow" />');   
</script>

But the W3C validator hates that crap: 但是W3C验证器讨厌这种废话:

document type does not allow element "span" here 文档类型此处不允许元素“ span”

What am I doing wrong? 我究竟做错了什么? Is there a way to correct this error, while maintaining the function? 在维护功能的同时,有没有办法纠正此错误?

Thanks! 谢谢!

I assume you're using XHTML? 我假设您正在使用XHTML? You need wrap your JavaScript in CDATA: 您需要将JavaScript包装在CDATA中:

<script type="text/javascript">
//<![CDATA[
        $('blockquote.message').append('<span class="arrow" />');       
//]]>
</script>

See the XHTML reference here: http://xhtml.com/en/xhtml/reference/script/ - "If the script element contains embedded script and that script contains XHTML markup characters such as <, >, & and ", then the script should be enclosed in CDATA" 请参阅此处的XHTML参考: http : //xhtml.com/en/xhtml/reference/script/- “如果script元素包含嵌入式脚本,并且该脚本包含XHTML标记字符,例如<,>,&和“,则脚本应包含在CDATA中”

blockquote标签只能包含块元素,例如P,H1..n,OL / UL,PRE,DL,DIV,NOSCRIPT,BLOCKQUOTE,FORM,HR,TABLE,FIELDSET,ADDRESS

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

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