문제

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