【发布时间】:2018-03-29 14:48:01
【问题描述】:
我正在尝试在 javascript 中处理 keydown 事件,但目前我遇到了以前从未发生过的事情:
var maxL = $("#myField").attr("maxLength")
console.log("Maximum Length : " + maxL);
if (e.key.length === 1 && str.length >= parseInt(maxL)) {
console.log(">>>> in if");
console.log(">>>> e.char == \"" + e.key + "\"");
e.preventDefault();
}
当我加载页面时,它失败了。在调试时,我的服务器控制台会记录此错误:
Error Parsing /folder/myPage.xhtml: Error Traced[line: 384] The entity name
must immediately follow the '&' in the entity reference.
其中 384 是 if 所在的行
我分别尝试了这两个条件,它们工作得很好,这让我认为“&&”运算符有问题。
如果这很重要,我使用 PrimeFaces 在 JSF 中的 WebSphere 服务器上工作,并尝试在 Chrome 中运行它。 javascript 嵌入在 div 中,以便在页面加载后将其删除:
<div id="deleteScript">
<SCRIPT>
//my script code
$("#deleteScript").remove();
</SCRIPT>
</div>
【问题讨论】:
-
您使用的是哪种浏览器?
-
chrome : 好点
-
看起来 jsf 正在解释你的 js 的一部分,就好像它是 EL 一样。用
<![CDATA[和]]>包装你的脚本(在<script>标签之后) -
实际上不是重复的,而是相同的解决方案stackoverflow.com/questions/17443461/…
-
需要更多执行上下文。代码很好。
标签: javascript xhtml logical-operators