在Mozilla中使用materpage的mypage中,javascript keypress/keydown事件不起作用 [英] javascript keypress/keydown event is not working in mypage which is using materpage in Mozilla
本文介绍了在Mozilla中使用materpage的mypage中,javascript keypress/keydown事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码如下,如果我使用与母版页相同的代码,则可以正常工作,但是使用母版页,
它没有调用keypress/keydown事件.
My code is as follows, if i use the same code wihtout master page, it is working, but with master page,
it is not calling keypress/keydown event.
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/jscript" >
function test() {
alert("hai");
}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:TextBox ID="emptxtbox" Text="" MaxLength="4" runat="server"
onkeydown="return test();" Width="200px" Height="50px"
Font-Size="XX-Large" />
</asp:Content>
推荐答案
请参考类似的讨论:
按键事件在mozilla Firefox中不起作用 [ ^ ]
onkeypress()不起作用 [ jQuery keypress()事件未触发 [ JavaScript疯狂:键盘事件 [
Please refer similar discussion:
Key press event is not working in mozilla fire fox[^]
onkeypress() not working[^]
jQuery keypress() event not firing[^]
Have a look on: JavaScript Madness: Keyboard Events[^] for more information.
尝试一下,这两种方法都可以使用:
try this , it works in both:
function isNumericKeyStroke(evt) {
var returnValue = false;
var charCode = (window.Event) ? evt.which : evt.keyCode
if (((charCode >= 48) && (charCode <= 57)) || // All numerics
(charCode == 8) || // Backspace
(charCode == 13)) // Carriage Return
{
returnValue = true;
}
return returnValue;
}
这是一个已知问题,并且 ^ ].
FF不会将window.event用于按键,但希望将事件作为参数传递给处理该事件的函数
在此处查看"Fang"答案,以获取有关如何处理它的类似讨论: window.event.keycode 13韩元"无法在Firefox中工作 [^ ]
另一个有用的链接: http://www.ryancooper.com/resources/keycode.asp [ ^ ]
It is a known issue and multiple discussions[^] can be found on internet.
FF doesn''t use window.event for keypress, but expects the event to be passed as a parameter to the function handling it
Look ''Fang'' answer here for similar discussion on how to handle it: window.event.keycode 13 won''t work in Firefox[^]
Another link that will help: http://www.ryancooper.com/resources/keycode.asp[^]
这篇关于在Mozilla中使用materpage的mypage中,javascript keypress/keydown事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文