最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

genshi and javascript ampersand? - Stack Overflow

programmeradmin2浏览0评论

I have the following javascript in my genshi template and I'm unsure how to get it to parse without errors:

floor = (!floor && floor !== 0)? 20 : floor;

I tried this:

floor = (!floor &amp&amp floor !== 0)? 20 : floor;

but it always produces this error:

'genshi.template.base.TemplateSyntaxError'> at not well-formed (invalid token)

any thoughts?

I have the following javascript in my genshi template and I'm unsure how to get it to parse without errors:

floor = (!floor && floor !== 0)? 20 : floor;

I tried this:

floor = (!floor &amp&amp floor !== 0)? 20 : floor;

but it always produces this error:

'genshi.template.base.TemplateSyntaxError'> at not well-formed (invalid token)

any thoughts?

Share Improve this question edited Nov 6, 2018 at 1:19 lucascaro 19.6k4 gold badges42 silver badges48 bronze badges asked Mar 1, 2012 at 22:41 user257543user257543 8912 gold badges14 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

The trick was to wrap the JS code in CDATA tags to hide the js from genshi but ALSO ment the cdata tags out for javascript

<script type="text/javascript">
    //<![CDATA[
    floor = (!floor && floor !== 0)? 20 : floor;
    // ]]>
</script>

You forgot the semicolons.

Does this work?

&amp;&amp;

If not, you could just cheat and rewrite it to not use ampersands.

floor = floor === 0 ? 0 : floor || 20;
发布评论

评论列表(0)

  1. 暂无评论