keydown事件不适用于Chrome

编程入门 行业动态 更新时间:2024-10-22 13:53:39
本文介绍了keydown事件不适用于Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有两个文本框和一个按钮的asp表单。

I have an asp form with two textboxes and one button. I have implemented the code to fire the click event of the button on enter key press.

<asp:LinkButton ID="statementSearchButton" runat="server" OnClick="GetSearchResults" class="enterButton"> </asp:LinkButton> $(document).keydown(function (event) { if (event == undefined) { event = window.event; } if (event.keyCode == 13) { $('.enterButton').focus(); $('.enterButton').click(); } });

这适用于IE和Firefox,但不适用于Chrome。我使用开发人员工具在Chrome中调试JS,发现如果block被执行但是click事件没有被解雇,keycode内部的语句== 13。任何想法解决这个问题?

This works fine in IE and Firefox but not in Chrome. I debugged the JS in Chrome using Developer tools and found that the statements inside the keycode == 13 if block are executed but the click event is not getting fired somehow. Any idea to fix this problem?

推荐答案

它适用于我。

我使用JQuery 1.7.2和Google Chrome 18.0.1025.168(官方版本134367)

I'm using JQuery 1.7.2, and Google Chrome 18.0.1025.168 (Official Build 134367)

$(document).keydown(function (event) { if (event == undefined) { event = window.event; } if (event.keyCode == 13) { alert("keyCode 13"); $('#kplay').focus(); $('#kplay').click(); } }); $("#kplay").click(function(event) { alert('#kplay clicked'); });

我也使用.kplay而不是#kplay进行了检查,结果没有问题。

I also checked with .kplay instead of #kplay, and that worked without issue.

$(document).keydown(function(event){ if (event.which == 13) $('.kplay').click(); });

更多推荐

keydown事件不适用于Chrome

本文发布于:2023-11-23 14:05:22,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   事件   keydown   Chrome

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!