I am using Genshi template engine in the Turbogears2 web framework. While writing the simple javascript if statement, I am getting the error "Unexpected token ; ". I am comparing few things in the table and printing its value if it is greater than some value. It is similar to this code:

"var c = 4;
if (c > 3) {
console.log(c); }"

Could someone help me out from this problem.

Thanks

有帮助吗?

解决方案

Always emit your javascript in CDATA sections:

<script>
//<![CDATA[ 
var c = 4;
if (c > 3) {
  console.log(c); 
}
//]]>
</script>

That way they will be correctly handled while still making possible to use ${} expressions inside your JS

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top