jQuery 浏览器中的 autocomplete="off" 强制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18123683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
autocomplete="off" force in browser
提问by Sunny Patel
I have a login form and I NEED to force autocomplete to off. i have tried
我有一个登录表单,我需要强制关闭自动完成功能。我试过了
jquery: $('#login').attr("autocomplete", "off");
查询: $('#login').attr("autocomplete", "off");
HTML: <input ... autocomplete="off">
HTML: <input ... autocomplete="off">
Javascript: document.getElementById('myInputId').autocomplete = 'off';
Javascript: document.getElementById('myInputId').autocomplete = 'off';
When I click the login input box a drop down appears
across all browsers
FF, Chrome, IE..
当我单击登录输入框时,所有浏览器都会出现一个下拉列表
FF, Chrome, IE..
N.B. this applies to users who have previously saved password information They need to forced to enter login details
注意这适用于以前保存过密码信息的用户他们需要强制输入登录详细信息
回答by Vitor Schweder
Or add with jQuery: $("input, select, textarea").attr("autocomplete", "off");
或者用 jQuery 添加: $("input, select, textarea").attr("autocomplete", "off");
回答by Stefano Altieri
The W3Schoolsstates (tested):
在W3Schools的状态(测试):
<input type="email" name="email" autocomplete="off" />
Please note that this is defined in HTML5
请注意,这是在 HTML5 中定义的
For previous version see this SO
对于以前的版本,请参阅此 SO
回答by CallMeKat
Worked for Chrome onFocus remove readonly - but onBlur you have to re-write it. So:
适用于 Chrome onFocus 删除只读 - 但 onBlur 你必须重新编写它。所以:
onFocus="this.removeAttribute('readonly');"
onBlur="this.setAttribute('readonly', true);"
This did the trick. For IE and Firefox I added in any case the autocomplete="off"
with jQuery on "ready" function to all fields that might need it (marking them with a class (or cssclass):
这成功了。对于 IE 和 Firefox,我在任何情况下autocomplete="off"
都向所有可能需要它的字段添加了with jQuery on“ready”函数(用类(或 cssclass)标记它们):
$(document).ready(function () {
$(".noautocomplete").attr("autocomplete", "off");
});
回答by Waseem Siddiqui
Try this
尝试这个
Add disabled attribute to the form fields( email, password, etc.)
syntax: <input type="email" name="email" class="email" autocomplete="off" disabled />
On Page Load enable the fields after few miliseconds.
use the below JS CODE.
function getRidOffAutocomplete(){ var timer = window.setTimeout( function(){ $('.email').prop('disabled',false); clearTimeout(timer); }, 800); } // Invoke the function, handle page load autocomplete by chrome. getRidOffAutocomplete();
向表单字段(电子邮件、密码等)添加禁用属性
syntax: <input type="email" name="email" class="email" autocomplete="off" disabled />
在页面加载上,几毫秒后启用这些字段。
使用下面的 JS 代码。
function getRidOffAutocomplete(){ var timer = window.setTimeout( function(){ $('.email').prop('disabled',false); clearTimeout(timer); }, 800); } // Invoke the function, handle page load autocomplete by chrome. getRidOffAutocomplete();
回答by Murat Y?ld?z
Try this:
尝试这个:
$(document).ready(function(){
$( document ).on( 'focus', ':input', function(){
$( this ).attr( 'autocomplete', 'off' );
});
});
Or this:
或这个:
$(document).ready(function(){
$("input").attr("autocomplete", "off");
});
On the other hand, you might have a look at this Chrome Browser Ignoring AutoComplete=Off. Hope this helps..
另一方面,您可能会查看此Chrome 浏览器 Ignoring AutoComplete=Off。希望这可以帮助..