[英]How to correctly include javascript code in chameleon/zpt template (pyramid)?
I'm trying to embed some code between < script > < /script > tags, pyramid however doesn't like it and gives me 我正在尝试在< script > < / script >标签之间嵌入一些代码,金字塔然而不喜欢它并给我
ExpatError: not well-formed (invalid token) ExpatError:格式不正确(令牌无效)
Probably because i have && in my code. 可能是因为我的代码中有&&。 I tried using &
我试过用&
instead, but then it didn't get interpreted in the browser. 相反,但它没有在浏览器中解释。
The same thing happens when i try to put it in CDATA block. 当我尝试将其放入CDATA块时,会发生同样的事情。
When I move the code to a separate js file it works. 当我将代码移动到单独的js文件时,它可以工作。 I'd like to keep it in the same file for now, just to enable quick corrections. 我现在想把它保存在同一个文件中,只是为了快速修正。
So, how should I do it? 那么,我该怎么做呢?
EDIT: 编辑:
I get the same error even for templates as simple as this one: 即使对于像这样简单的模板,我也会得到同样的错误:
<html
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
</head>
<body>
<span onclick="alert(true && false);">test</span>
</body>
</html>
我认为你应该把&&(即HTML实体代码的两倍)。
This should work: 这应该工作:
<script type="text/javascript">
//<![CDATA[
// my javascript
//]]>
</script>
Have you tried adding a type
attribute to your script tag?: 您是否尝试过将type
属性添加到脚本标记中?:
<script type="text/javascript">
...
</script>
It looks like xhtml issue, as w3c validator reported the same error. 它看起来像xhtml问题,因为w3c验证器报告了同样的错误。
I was thinking if there's a switch to change the document type parsed by chameleon to html, but then it wouldn't be possible to include tal and metal namespaces. 我在想是否有转换将chameleon解析的文档类型更改为html,但之后不可能包含tal和metal命名空间。
Hence it is expected behavior 因此, 这是预期的行为
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.