如何绑定浏览器输入字段的更改? (jQuery的) [英] How to bind to browser change of input field? (jQuery)

查看:133
本文介绍了如何绑定浏览器输入字段的更改? (jQuery的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看看这个:
http://jsfiddle.net/sduBQ/1 /

Html:

<form action="login.php" method="post" id="login-form">
    <div class="field">
        <input name="email" id="email" type="text" class="text-input" value="E-mail" />
    </div>

    <div class="field">
        <input name="code" id="code" type="password" class="text-input" />
        <div id='codetip'>Access Code</div>
        <label class="error" for="code" id="code_error"></label>
    </div>
    <br />
    <div class="container">
        <a id="submit" class="link-2">Access</a>
     </div>
</form>

CSS:

a {
    border: solid 1px #777;
    padding:5px;
}
#codetip {
    position:absolute;
    margin-top:-20px;
    margin-left:5px;
}

Javascript:

Javascript:

$('#email').focus(function(){
    if($(this).val()=='E-mail'){$(this).val('');}
});
$('#email').blur(function(){
    if($(this).val()==''){$(this).val('E-mail');}
});

$('#code').focus(function(){
    $('#codetip').hide();
});
$('#code').blur(function(){
    if($(this).val()==''){$('#codetip').show();}
});

$('#codetip').click(function(){
    $(this).hide();
    $('#code').focus();
});

$('#submit').click(function(){
    $(this).submit();
});

问题是,至少在Chrome(还没有尝试过其他浏览器)时,Chrome密码经理保存您的密码,并在您选择电子邮件时预先填写密码。我使用jquery来隐藏/显示密码输入字段顶部的div作为标签,当用户点击密码字段时隐藏该div(从上面的jsfiddle代码可以看出)。我需要知道如何在Chrome预填密码字段时隐藏该div ...

The problem is that at least in Chrome(haven't tried other browsers yet) when the Chrome Password Manager saves your password and prefills the password for you when you pick the email. I use jquery to hide/show a div over the top of the password input field as a label, hiding that div when the user clicks into the password field (as can be seen in the above jsfiddle code). I need to know how to hide that div when Chrome prefills the password field...

推荐答案

我没有运行根据几个快速的Google搜索,这似乎是一个常见的问题。

I've haven't run into this myself, but it appears to be a common issue, based on a few quick Google Searches.

  • FireFox capture autocomplete input change event
  • http://bugs.jquery.com/ticket/7830

您可以做的一个简单的攻击是设置一些代码,每两秒通过 setInterval 运行,并检查该字段有一个价值。

One easy hack you could do is set up some code that runs every second or two via setInterval, and checks to see if the field has a value.

这样的东西...

var code = $('#code');
var codeTip = $('#codetip');
var interval = setInterval(function(){
    if (code.val()!=''){
        codeTip.hide();
        clearInterval(interval);
    }
}, 1000);

这篇关于如何绑定浏览器输入字段的更改? (jQuery的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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