Jquery在输入中禁用自动完成

Max*_*ain 19 javascript jquery autocomplete

我有这个代码:

html:

<input id="register_username" type="text">
<input id="register_password" type="text">
<input id="register_repeatpassword" type="text">
<input id="register_email" type="text">
Run Code Online (Sandbox Code Playgroud)

Jquery:

$(document).ready(function(){
    $('#register_username').attr('autocomplete','off');
    $('#register_password').attr('autocomplete','off');
    $('#register_repeatpassword').attr('autocomplete','off');
    $('#register_email').attr('autocomplete','off');
    });
Run Code Online (Sandbox Code Playgroud)

我想禁用某些浏览器的自动完成功能,并且实际上让用户键入整个字段但代码不起作用,下拉菜单仍然出现,用户仍然可以选择之前键入的内容.我也尝试过用户,autocomplete="off"但什么都没发生.我在这做错了什么?

Dav*_*ing 30

只需添加:

autocomplete="off"
Run Code Online (Sandbox Code Playgroud)

作为INPUT元素的属性,f.ex:

<input autocomplete="off" id="register_username" type="text" name="username">
Run Code Online (Sandbox Code Playgroud)


Car*_*ith 12

jQuery的版本:

$("#register_username").attr("autocomplete", "off");
Run Code Online (Sandbox Code Playgroud)

  • 无论如何,那是三年前的事了......今天我不打算对这样的事情发表评论,因为它对人们仍有帮助.:) (2认同)

Jar*_*red 11

如果有人来这里寻找如何关闭 jquery 自动完成功能:

$("#elementId").autocomplete({
  disabled: true
  });
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你的建议。尝试 $("#id").attr("autcomplete", "off") 或 false 或其他一些值不起作用,但您的解决方案起作用了。 (3认同)

raj*_*wat 6

检查这个捣鼓

 document.getElementById("register_username").autocomplete="off"
Run Code Online (Sandbox Code Playgroud)


Cav*_*ava 5

现在,您需要将“off”更改为另一个随机字符串,例如“nope”:

jQuery:

$("#register_username").attr("autocomplete", "nope");
Run Code Online (Sandbox Code Playgroud)

HTML:

<input id="register_username" type="text" autocomplete="nope">
Run Code Online (Sandbox Code Playgroud)