我正在使用登录表单,我在其上添加了Mootools OverText的“占位符” (* http://mootools.net/docs/more/Forms/OverText,http://mootools.net/demos/?demo=Enhanced-Form)。
问题是浏览器使用电子邮件/密码自动填充字段,并且它们显示在OverText下。 当浏览器填写字段时,有什么方法可以让翻译不显示? (*我想保持自动完成功能)
*当浏览器自动填充字段时,OverText显示在电子邮件/密码上:
**具有OverText的字段的正常视图:
<form id="user_form_login" action="/login">
<div id="email-wrapper" class="form-wrapper">
<div id="email-element" class="form-element">
<input type="email" name="email" id="email" value="" tabindex="1" class="text" autocomplete="off" title="<?php echo $this->translate('Email Address'); ?>">
</div>
</div>
<div id="password-wrapper" class="form-wrapper">
<div id="password-element" class="form-element">
<input type="password" name="password" id="password" value="" tabindex="2" title="<?php echo $this->translate('Password'); ?>">
</div>
</div>
</form>
<script type="text/javascript">
window.addEvent('domready', function(){
var LoginForm = $('user_form_login');
LoginForm.getElements('[type=email], [type=password]').each(function(el){
new OverText(el);
});
});
</script>
答案 0 :(得分:1)
试试这个:
<script type="text/javascript">
window.addEvent('domready', function(){
var LoginForm = $('user_form_login');
LoginForm.getElements('[type=email], [type=password]').each(function(el){
new OverText(el);
});
// *** New part ***
LoginForm.getElements('[type=email], [type=password]').addEvent('change', function () {
this.getNext('label').set('text', '');
});
});
</script>
修改强>
(自difficult以来检测自动填充的另一种选择)
var All_El = LoginForm.getElements('[type=email], [type=password]');
var re_check = setInterval(function () {
All_El.each(function (el) {
if (el.value != '') {
el.getNext('label').set('text', '');
}
});
}, 400);