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)


- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01