event.keyCode在Firefox中不起作用 [英] event.keyCode not working in Firefox

查看:137
本文介绍了event.keyCode在Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ASP.NET C#开发的登录页面遇到问题。
该表单适用于IE,但不适用于Firefox。
这是我的示例:

 <%@ Page Language =c#Inherits =ClubCard.loginClubcardCodeFile =loginClubcard.aspx.cs%> 
<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.0 Transitional // EN>
< html>
< head>
< title>
Acceso Clubcard
< / title>

< meta http-equiv =Page-Entercontent =blendTrans(Duration = 0.25)/>
< meta http-equiv =Page-Exitcontent =blendTrans(Duration = 0.25)/>
< link rel =stylesheettype =text / csshref =styles.css>

< style>
#centered
{
左:50%;
MARGIN-LEFT:-235px;
POSITION:absolute;
顶部:150px
}

.letras
{
FONT-SIZE:10pt;
颜色:白色;
FONT-FAMILY:Arial
}

.cajas
{
FONT-SIZE:10pt;
FONT-FAMILY:Arial
}

.letrasGris A
{
FONT-SIZE:12px;
颜色:#8f8f92;
FONT-FAMILY:Arial;
TEXT-DECORATION:none
}

.highlightit IMG
{
FILTER:progid:DXImageTransform.Microsoft.Alpha(opacity = 100);
-moz-opacity:1
}

.highlightit:hover IMG
{
FILTER:progid:DXImageTransform.Microsoft.Alpha(opacity = 50 );
-moz-opacity:0.5
}
< / style>

< script language =javascript>
function actLogin()
{
__doPostBack('btnLogin','');
}

函数actFocus()
{
tbxPrincipal = document.getElementById(tbxUsername)。
}

函数ValidarEnter(src)
{
if(event.keyCode ==13)
{
actLogin() ;
}
}

函数AbrirLogin()
{
if(window.frameElement!= null)
{
window .parent.location.replace(window.location.href);
}
}
< / script>

< meta name =GENERATORcontent =Microsoft Visual Studio .NET 7.1>
< meta name =CODE_LANGUAGEcontent =C#>
< meta name =vs_defaultClientScriptcontent =JavaScript>
< meta name =vs_targetSchemacontent =http://schemas.microsoft.com/intellisense/ie5>
< / head>

< body bgcolor =#ffffffleftmargin =0topmargin =0onload =AbrirLogin(); actFocus()>
< form id =Form1method =postrunat =servertarget =_ top>
< table id =Table_01width =100%height =100%border =0cellpadding =0cellspacing =0>
< tr>
< td style =background:url(images / login / loginBg.gif)repeat-x>
& nbsp;
< / td>
< / tr>
< / table>

< div id =center>
< div style =left:50%; margin-left:-100px; position:absolute>
< div>
< img src =images / login / logoClubCard.gif>
< / div>
< / div>

< div style =margin-left:100px; width:200px; position:absolute; top:240px>
< table width =100%cellpadding =0cellspacing =2border =0>
< tr>
< td align =rightclass =letras>
USUARIO:
< / td>

< td>
< asp:TextBox runat =serverCssClass =cajasID =tbxUsername>
< / asp:TextBox>
< / td>

< td rowspan =3>
& nbsp;& nbsp;
< a class =highlightithref =javascript:actLogin()tabindex =3>
< img border =0src =images / login / botonLogin.gif>
< / a>
< / td>
< / tr>

< tr>
< td align =rightclass =letras>
CLAVE:
< / td>

< td>
< asp:TextBox runat =serverCssClass =cajasID =tbxPasswordTextMode =PasswordOnKeyPress =ValidarEnter(this)OnTextChanged =tbxPassword_TextChanged>
< / asp:TextBox>
< / td>
< / tr>
< / table>
< / div>

< div style =margin-top:54px>
< img src =images / login / cajaAzul.gif>
< / div>

< div style =display:inline; float:left; width:50%align =center>
< asp:RequiredFieldValidator ID =rfvUsernamerunat =server
CssClass =tAErrorMessage =* Escriba su USUARIO
ControlToValidate =tbxUsername>
< / asp:RequiredFieldValidator>

< br>

< asp:RequiredFieldValidator ID =rfvPasswordrunat =server
CssClass =tAErrorMessage =* Escriba su CLAVE
ControlToValidate =tbxPassword> ;
< / asp:RequiredFieldValidator>

< br>

< table>
< tr align =center>
< td>
< asp:Label runat =serverID =lblErrorVisible =False>
< font color =redclass =tA>
< b>
El USUARIO y CLAVE no coincidieron,trate de nuevo
< / b>
< / font>
< / asp:Label>
< / td>
< / tr>
< / table>
< / div>
< / div>

< div style =display:none>
< input type =buttonrunat =serverid =btnLoginvalue =loginonserverclick =btnLogin_ServerClick>
< / div>
< / form>
< / body>
< / html>

我注意到在这一部分...

 函数ValidarEnter(src)
{
if(event.keyCode ==13)
{
actLogin );
}
}

当我在firefox中调试它时,它只是跳过它。
我已经尝试添加 window.event.keyCode ...并且只需13 ...
即可切换13在这个工作吗?

解决方案

Firefox不支持event.keycode。使用event.which for firefox。

  function checkKey(evt){
var keyID =(evt.charCode)? evt.charCode:((evt.which)?evt.which:evt.keyCode);
alert(keyID);
}


I'm having a problem with a Login page I'm developing on ASP.net C#. The form works on IE, but not Firefox. Here's my sample:

<%@ Page Language="c#" Inherits="ClubCard.loginClubcard" CodeFile="loginClubcard.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<html>
    <head>
        <title>
            Acceso Clubcard
        </title>

        <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.25)" />
        <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.25)" />
        <link rel="stylesheet" type="text/css" href="styles.css">

        <style>
            #centered
            {
                LEFT: 50%;
                MARGIN-LEFT: -235px;
                POSITION: absolute;
                TOP: 150px
            }

            .letras
            {
                FONT-SIZE: 10pt;
                COLOR: white;
                FONT-FAMILY: Arial
            }

            .cajas
            {
                FONT-SIZE: 10pt;
                FONT-FAMILY: Arial
            }

            .letrasGris A
            {
                FONT-SIZE: 12px;
                COLOR: #8f8f92;
                FONT-FAMILY: Arial;
                TEXT-DECORATION: none
            }

            .highlightit IMG
            {
                FILTER: progid:DXImageTransform.Microsoft.Alpha(opacity=100);
                -moz-opacity: 1
            }

            .highlightit:hover IMG
            {
                FILTER: progid:DXImageTransform.Microsoft.Alpha(opacity=50);
                -moz-opacity: 0.5
            }
        </style>

        <script language="javascript">            
            function actLogin()
            {
                __doPostBack('btnLogin', '');
            }

            function actFocus()
            {
                tbxPrincipal = document.getElementById("tbxUsername").focus();
            }

            function ValidarEnter(src)
            {
                if (event.keyCode == "13")
                {
                    actLogin();
                }
            }

            function AbrirLogin() 
            { 
                if (window.frameElement != null) 
                { 
                    window.parent.location.replace(window.location.href); 
                } 
            } 
        </script>

        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </head>

    <body bgcolor="#ffffff" leftmargin="0" topmargin="0" onload="AbrirLogin();actFocus()">
        <form id="Form1" method="post" runat="server" target="_top">
            <table id="Table_01" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td style="background: url(images/login/loginBg.gif) repeat-x">
                        &nbsp;
                    </td>
                </tr>
            </table>

            <div id="centered">
                <div style="left: 50%; margin-left: -100px; position: absolute">
                    <div>
                        <img src="images/login/logoClubCard.gif">
                    </div>
                </div>

                <div style="margin-left: 100px; width: 200px; position: absolute; top: 240px">
                    <table width="100%" cellpadding="0" cellspacing="2" border="0">
                        <tr>
                            <td align="right" class="letras">
                                USUARIO:
                            </td>

                            <td>
                                <asp:TextBox runat="server" CssClass="cajas" ID="tbxUsername">
                                </asp:TextBox>
                            </td>

                            <td rowspan="3">
                                &nbsp;&nbsp;
                                <a class="highlightit" href="javascript:actLogin()" tabindex="3">
                                    <img border="0" src="images/login/botonLogin.gif">
                                </a>
                            </td>
                        </tr>

                        <tr>
                            <td align="right" class="letras">
                                CLAVE:
                            </td>

                            <td>
                                <asp:TextBox runat="server" CssClass="cajas" ID="tbxPassword" TextMode="Password" OnKeyPress="ValidarEnter(this)" OnTextChanged="tbxPassword_TextChanged">
                                </asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </div>

                <div style="margin-top: 54px">
                    <img src="images/login/cajaAzul.gif">
                </div>

                <div style="display: inline; float: left;width:50% " align="center">
                    <asp:RequiredFieldValidator ID="rfvUsername" runat="server" 
                        CssClass="tA" ErrorMessage="* Escriba su USUARIO"
                        ControlToValidate="tbxUsername">
                    </asp:RequiredFieldValidator>

                    <br>

                    <asp:RequiredFieldValidator ID="rfvPassword" runat="server" 
                        CssClass="tA" ErrorMessage="* Escriba su CLAVE"
                        ControlToValidate="tbxPassword">
                    </asp:RequiredFieldValidator>

                    <br>

                    <table >
                        <tr align="center">
                            <td>
                                <asp:Label runat="server" ID="lblError" Visible="False">
                                    <font color="red" class="tA">
                                        <b>
                                            El USUARIO y CLAVE no coincidieron, trate de nuevo
                                       </b>
                                    </font>
                                </asp:Label>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

            <div style="display: none">
                <input type="button" runat="server" id="btnLogin" value="login" onserverclick="btnLogin_ServerClick">
            </div>
        </form>
    </body>
</html>

I'm noticing that in this part...

function ValidarEnter(src)
            {
                if (event.keyCode == "13")
                {
                    actLogin();
                }
            }

When I debug it on firefox, it just skips it. I have already tried to add window.event.keyCode... and also switch "13" with just 13... How could I work this around?

解决方案

event.keycode was not supported by Firefox. Use event.which for firefox.

function checkKey(evt) {
  var keyID = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
  alert(keyID);
}

这篇关于event.keyCode在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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