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

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
刘奇

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&gt ;
<script>

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!