Enter 键预防 Javascript 不适用于 IE 中的 JSF 1.1
环境注释:使用 Infragistics 组件库的 JSF 1.1。
我正在使用以下 Javascript 尝试阻止“Enter”按键提交表单。
function disableEnterKey(e){
var key;
if(window.event)
key = window.event.keyCode;
else
key = e.which;
return (key != 13);
}
然后在 JSP 中,我有:
<h:inputText id="an_id" value="#{bean.value}"
onkeypress="return disableEnterKey(event);" />
这似乎在 Firefox 和 Google Chrome 中完美运行。我不明白为什么它不适用于 IE8。我很困惑。
我尝试过使用 Tomahawk
,但这没有什么区别。
我尝试在父
和/或 元素的
onkeypress
处理程序中添加一些内容,但这似乎也没有帮助。而且,我尝试过使用 onkeydown
,但也没有看到任何区别。
我认为我提出的鉴别诊断是它可能与Infragistics 库有关。 IG 确实向页面添加了相当多的脚本,但我不太清楚如何使用 IE8 有效地调试 Javascript。在 FF 上使用 Firebug 来解决这个问题是没有问题的,但我有点难住了。
有人有类似的经历吗?知道修复吗?
Notes on environment: JSF 1.1 using Infragistics component library.
I'm using the following Javascript to attempt to prevent an 'Enter' keypress from submitting a form.
function disableEnterKey(e){
var key;
if(window.event)
key = window.event.keyCode;
else
key = e.which;
return (key != 13);
}
Then in the JSP, I have:
<h:inputText id="an_id" value="#{bean.value}"
onkeypress="return disableEnterKey(event);" />
This seems to work flawlessly in Firefox and Google Chrome. I don't understand why it doesn't work with IE8. I'm stumped.
I've tried using a Tomahawk <t:inputText/>
, but that doesn't make a difference.
I've tried putting something in the onkeypress
handler for the parent <h:form>
and/or the <body>
element, but that doesn't seem to help either. And, I've tried using the onkeydown
, but haven't seen a difference with that, either.
The differential diagnosis that I think I have come up with is that it may have something to do with the Infragistics library. IG does add quite a bit of scripting to pages, but I'm not solid on how to debug Javascript effectively with IE8. This would be no problem to poke through with Firebug on FF, but I'm a bit stumped.
Anyone have a similar experience? Know of a fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道现在有点晚了,但这适合其他尝试做这件事的人。
如果您的页面仅包含一个
h:inputText
,则会出现此问题。添加另一个类似的隐藏文本可以解决问题。
I know it is bit late, but this is for others who try to do this thing.
This problem occurs if your page contains only one
h:inputText
.Add another like hidden text this resolves problem.
奇怪的事情,因为它在 IE8 和 FF 中只适用于我:
weird thing, because it works for me in IE8 and in FF only this way:
这是解决这个问题的唯一办法!
This was the only way to solve this!