FireFox事件处理 [英] FireFox event handling

查看:61
本文介绍了FireFox事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道有没有人知道为什么现在这样做:



Wonder if anyone knows why this does now work:

<asp:TextBox Width="50" ID="TB1" runat="server" onKeyPress="CatchEnter(event.keyCode)"/>

<asp:DropDownList runat="server" onKeyPress="CatchEnter(event.keyCode)" />

    <div style="display:none">
    <asp:Button ID="btnLogin"

                runat="server"

                OnClick="btnLogin_Click" />
    </div>

<script type="text/javascript">
    function CatchEnter(e) {
        if (e == 13) {
            alert("caught");
        }
    }
</script>





所以 - 我们有一个TextBox和DropDownList。两者都有onKeyPress事件处理程序,但由于某些原因,FireFox在TextBox中按Enter工作,而不是在DropDownList上。使用DropDownList我必须按ALT + Enter才能实现它?虽然它适用于IE和Chrome。



任何人都知道解决方法吗?



谢谢!



So - we have an TextBox and DropDownList. Both have onKeyPress event handler, but for some reasons on FireFox pressing "Enter" in TextBox works and does not on DropDownList. With DropDownList I have to press ALT + Enter to make it happen? Though it works on IE and Chrome.

Anyone knows a workaround?

Thanks!

推荐答案

请尝试使用KeyDown代替KeyEnter..



尝试如果它的工作在你的情况请接受...
Please try to use "KeyDown" instead of "KeyEnter"..

Try it If its work in your case please accept it...


尝试下面的代码

try below code
onKeyPress="CatchEnter(event.keyCode? event.keyCode : event.charCode)" 


尝试了我能想到的一切...但只有这个能够捕捉真正的Enter按钮按下< asp:dropdownlist xmlns:asp =#unknown>



Tried everything that I could think of... but only this worked to catch real Enter button press on <asp:dropdownlist xmlns:asp="#unknown">

window.onkeydown = function (e) {
        if (e.keyCode == 13)
        {
            document.getElementById("<%=MyButtonID.ClientID %>").click();
        }
    }





不知道为什么,但是使用windows.onkeypress它不适用于FireFox v29。 ..

无论如何 - 希望有人觉得这很有用。



干杯!



Not sure why, but with windows.onkeypress it does not work with FireFox v29...
Anyways - hope someone finds this useful.

Cheers!


这篇关于FireFox事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆