我网页上有几个文本框,但是自动填充功能很烦人。有没有办法从我的网站上移除它?
我网页上有几个文本框,但是自动填充功能很烦人。有没有办法从我的网站上移除它?
自 HTML 5 开始,自动完成是由所有主流浏览器支持的 表单/输入属性。
<form name="form1" id="form1" method="post" autocomplete="off" action="#">
此外,您可以在这里查看有关其使用的更多信息:
如果您正在准备一个网络应用程序或任何其他智能手机友好的网页,您可能想知道如何:禁用自动完成、自动大写和自动纠正。
<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
<textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
autocomplete="off"
作为表单属性添加,它将应用于表单内的所有字段。<form action="#" autocomplete="off">
以下是如何实现此操作的方法。
autocomplete="new-text"
autocomplete="off"不支持,可以使用'autocomplete="new-password"'代替。
<script type="text/javascript" language="javascript">
jQuery(function() {
jQuery('#my_input').attr('autocomplete', 'off');
});
</script>
<input type="text" name="my_input" id="my_input">
最简单的方法:
删除name
属性,然后在autocomplete
中始终添加一个不同的字符串。
$(document).ready(function () {
setTimeout(function () {
var randomicAtomic = Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10);
$('input[type=text]').removeAttr('name');
$('input[type=text]').attr('autocomplete', randomicAtomic);
}, 1000);
})
在 Html.BeginForm 中使用 autocomplete = "off"
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { @id = "myForm", @autocomplete = "off" }))
{
@Html.EditorFor(model => model.field, new { htmlAttributes = new { @class = "text-box form-control" } })
<input type="submit" value="Save" />
}
autocomplete="off"
在 Firefox 中有效,但在 Ubuntu 上的 Chromium 浏览器中无效,因此需要检查浏览器是否为 Chromium 浏览器,如果是,则使用autocomplete="disabled"
,否则使用autocomplete="off"
。
var is_chrome = /chrome/.test( navigator.userAgent.toLowerCase() );
$("#mobile").prop("autocomplete", is_chrome ? 'disabled' : 'off');