开发者

jQuery template expression constraints

开发者 https://www.devze.com 2023-03-27 03:55 出处:网络
I have: <script id=\"foo\" type=\"text/x-jquery-tmpl\"> <p>${100 * parseInt(x)}</p> </script>

I have:

<script id="foo" type="text/x-jquery-tmpl">
  <p>${100 * parseInt(x)}</p>
</script>

When I do:

$('#foo').tmpl({'x':5}) // or '5'

I get a TypeError (undefined method).

But if I remove the parseInt or if I move the 100 to come after the parseInt, everything works!

I've been searching and everything I find says th开发者_如何学JAVAat ${} should be able to handle arbitrary expressions, but there seems to be some syntax magic/intolerance going on here.

Any explanations?


You need to do like this:

 <p>100 * parseInt(${x})</p>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号