How to bind to browser change of input field? (jQuery)(如何绑定到输入字段的浏览器更改?(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 捕获自动完成输入更改事件
- 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何绑定到输入字段的浏览器更改?(jQuery)


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01