的KeyUp /的KeyDown键code没有密码领域的工作在IE浏览器? [英] KeyUp/KeyDown keyCode Not Working on Password Fields in IE?

查看:109
本文介绍了的KeyUp /的KeyDown键code没有密码领域的工作在IE浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表格

<asp:TextBox ID="txtUsername" runat="server" CssClass="watermarkOn" TabIndex="1" />
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="watermarkOn" TabIndex="2" />
<asp:LinkButton ID="btnLogin" runat="server" CssClass="imgbtn_login" TabIndex="3" Text="login" onclick="btnLogin_Click" CausesValidation="false" />

通过下面的jQuery

With the following jQuery

$(document).ready(function () {
    $("#<%=txtUsername.ClientID %>").keydown(function (event) {
        if (event.keyCode == 13) {
            eval($("#<%=btnLogin.ClientID %>").attr('href'));
        }
    });
    $("#<%=txtPassword.ClientID %>").keydown(function (event) {

        if (event.keyCode == 13)
        {
            eval($("#<%=btnLogin.ClientID %>").attr('href'));
        }
    });
});

这在FF,IE7,IE 9,Chrome浏览器,Safari浏览器完全罚款....但有一个例外。某些IE8安装它为用户名框,但不输入密码框。有谁知道为什么会出现这种情况。我没有看到周围有差别的任何文档中行为密码箱。

This works perfectly fine in FF, IE7, IE 9, Chrome, Safari....with one exception. Certain IE8 installations it works for the username box, but not for the password box. Does anyone know WHY this might be the case. I don't see any documentation around a difference in behavior for Password boxes.

更新

我也试过KEYUP,以及event.which,两者都不工作,要么。用户名框工作正常,但密码框不会引发像它应该。

I've also tried keyup, as well as event.which, neither of which work either. Username box works fine, but the password box does not trigger like it should.

推荐答案

直接在密码字段附加的关键preSS处理器并没有为我无论是在IE浏览器,但你可以尽管它连接到它的父:

Attaching the keypress handler directly on the password field didn't work for me either in IE, but you can attach it to its parent though:

<script type="text/javascript">
$("#loginForm").keypress(function(e) {
    if (e.keyCode == $.ui.keyCode.ENTER) {
        // do your thing :)
    }
});
</script>

<form id="loginForm" action="...">
  <input type="text" id="username" value="" />
  <input type="password" id="password" />
  ...
</form>

这篇关于的KeyUp /的KeyDown键code没有密码领域的工作在IE浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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