简体   繁体   English

有没有办法使用jQuery在输入字段上关闭自动完成功能?

[英]Is there a way to turn off auto-complete on an input-field using jQuery?

Is there a way to turn off auto-complete on an input-field using jQuery? 有没有办法使用jQuery在输入字段上关闭自动完成功能?

Like this: 像这样:

<input type="text" autocomplete="off" />
$(':text').attr('autocomplete', 'off');
$('input#id').attr('autocomplete', 'off');

You can also use a common class to turn off a group of fields. 您也可以使用通用类关闭一组字段。 There are a few ways to do it though as you'll see from the answers. 从答案中可以看出,有几种方法可以做到这一点。

$('#id').attr('autocomplete', 'off');

For any text field, you could do this. 对于任何文本字段,都可以执行此操作。

$("input[type=text]").attr("autocomplete", "off");

Hope this helps! 希望这可以帮助!

"autocomplete" isn't a standard attribute. “自动完成”不是标准属性。 Yes it's implemented, but it's not proper XHTML. 是的,它已经实现了,但是它不是正确的XHTML。

Do you have to do it client-side? 您必须在客户端执行此操作吗? Can you make changes on the server-side if necessary? 如有必要,您可以在服务器端进行更改吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM