XHTML不会验证&&和<在JavaScript函数中 [英] XHTML won't validate && and < in a JavaScript function

查看:130
本文介绍了XHTML不会验证&&和<在JavaScript函数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是无法验证的代码片段:

Here's the snippet of code that won't validate:

if (user_age > 15 && user_age < 91)

它出现以下错误:


XML解析错误:StartTag:无效的元素名称

XML Parsing Error: StartTag: invalid element name


XML解析错误:xmlParseEntityRef:无名称

XML Parsing Error: xmlParseEntityRef: no name

第一个错误是投掷小于,第二个抛出两次,每次投放一次。

The first error is thrown for the "less than" and the second one is thrown twice, once for each ampersand.

替换上述标志& < 验证正常,但当然它完全破坏了该功能。

Replacing the above signs with & and < validates fine, but of course it completely ruins the function.

推荐答案

或者您可以像这样保护脚本免受xml验证:

Or you can protect the script from the xml validation like this:

<script type="text/javascript"> 
//<![CDATA[
    if (user_age > 15 && user_age < 91) {
        // do soemthing
    }
//]]>
</script> 

这篇关于XHTML不会验证&amp;&amp;和&lt;在JavaScript函数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆