javascript - onfocus="this.type='password'", why not just use type='password'
怪我咯2017-06-28 09:27:57
0
2
919
When I saw a piece of code from someone else, why did the password input box use onfocus="this.type='password'" instead of using type='password' directly? Placeholder setting prompts
I know the answer. It turns out that it is to prevent the browser from remembering the password. In fact, there is an autocomplete='off' attribute. At the beginning, the type attribute of the password box is set to text, and when it gets the focus, it is changed to password. However, in the latest Firefox The method of changing to version 54 is useless, the password will still be remembered, but the password will not be remembered in chrome
document.querySelector("#psd").onfocus = function () {
this.type = 'password';
}
</script> The two have the same effect and <input type="text" onfocus="this.type='password'"/> You can put a breakpoint on the console to indicate that the two effects should be Same
I know the answer. It turns out that it is to prevent the browser from remembering the password. In fact, there is an autocomplete='off' attribute. At the beginning, the type attribute of the password box is set to text, and when it gets the focus, it is changed to password. However, in the latest Firefox The method of changing to version 54 is useless, the password will still be remembered, but the password will not be remembered in chrome
<body>
<input type="text" onfocus="this.type='password'"/>
<input type="text" id="psd"/>
</body> ;
<script>
</script>
The two have the same effect and <input type="text" onfocus="this.type='password'"/> You can put a breakpoint on the console to indicate that the two effects should be Same