XHTML won't validate && and < in a JavaScript function

点点圈 提交于 2019-11-29 03:42:55

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> 

Move script to other file :)

It is standard (and good) habit to separate style (into .css file), data (.html) and of course scripts to .js file.

All Javascript should be CDATA in XHTML:

<![CDATA[
if (user_age > 15 && user_age < 91)
]]>

put javascript in <![CDATA[...]]> section

you can try CDATA but some time it wont work, it depends on the setting of the server I guess. I am not a pro, but i tested, and I did not work, but if you put the javascript code in the .js file and then link this file somewhere in your body. it will definitely work. PERSONALLY TESTED.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!