简体   繁体   中英

Turn off autoComplete for all inputs in React app

This answer explains how to turn off autocomplete for an entire HTML document with jQuery .

Without jQuery is there a way to turn "off" React's equivalent autoComplete for all inputs within the app?

I'm not very familiar with jQuery otherwise I'd try to convert the function myself.

To disable the autocomplete for input fields in React, we need to set the input field's autoComplete attribute to "new-password".

<input type="email" name="email_signup" placeholder="Email" autoComplete="new-password" />
<input type="password" name="password_signup" placeholder="Password" autoComplete="new-password" />

This will turn off autocomplete for input.

You can use autocomplete="off" on the parent level of the form and that will turn it off for the entire form

<form method="post" action="/form" autocomplete="off">
[…]
</form>

在元素中使用它:

autoComplete:'off' 

The post that you are linking is just assigning the autocomplete off attribute to the document when it is loading. You can accomplish what jQuery is doing with something like the following using vanilla JS. However, I would suggest a more "React" way of doing things based on whatever logic you wish to accomplish.

var foo = document.querySelector("input"); 
foo.setAttribute("autoComplete", "off");

你可以用

<input name="myinput" placeholder="enter your name" value={this.input.myinput} autocomplete="off" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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