问题描述
不知道有没有人知道为什么现在这样做:
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!
推荐答案
onKeyPress="CatchEnter(event.keyCode? event.keyCode : event.charCode)"
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事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!