Javascript HTML/CSS:如何使“密码”输入显示密码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4004313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:06:30  来源:igfitidea点击:

HTML/CSS: How to make "password" input show the password?

javascripthtmlcsspasswords

提问by Andrei

How can you make the value in the password field visible? So, when typing your password in the field, it will not show the black dots, but the actual value that you are typing.

如何使密码字段中的值可见?因此,在字段中输入密码时,它不会显示黑点,而是显示您输入的实际值。

Thanks!

谢谢!

edit: Ok, so then a better question might be: How can I force the browser to remember the value in this 'password' field and treat it as a password?

编辑:好的,那么更好的问题可能是:如何强制浏览器记住此“密码”字段中的值并将其视为密码?

采纳答案by Brad

Don't make it a password field, make it a normal text box.

不要让它成为密码字段,让它成为一个普通的文本框。

If you need to switch the field type dynamically, there is a HOWOTO over on codingforums.com, and also several SO questions:

如果您需要动态切换字段类型,则在codingforums.com 上有一个HOWOTO,还有几个 SO 问题:

To ensure that browsers keep their normal behavior (saving/not saving passwords) you can convert this back to a password field upon submit.

为确保浏览器保持其正常行为(保存/不保存密码),您可以在提交时将其转换回密码字段。

回答by Pekka

How can you make the value in the password field visible? So, when typing your password in the field, it will not show the black dots, but the actual value that you are typing.

如何使密码字段中的值可见?因此,在字段中输入密码时,它不会显示黑点,而是显示您输入的实际值。

You can't.

你不能。

You can, however, use a normal text input for the user to type in the password.

但是,您可以使用普通文本输入让用户输入密码。

I wouldn't recommend this, though - for example, the browser might auto-save whatever you type in it. A autocomplete="off"is mandatory in any case.

不过,我不建议这样做 - 例如,浏览器可能会自动保存您输入的任何内容。Aautocomplete="off"在任何情况下都是强制性的。

Reference:

参考:

回答by svk

Then is it called password?It is simple text box only.

那么它叫密码吗?它只是简单的文本框。

<input type="text" name="password" id="password" />

Edit:Whether you want like a remember my password?

编辑:你是否想像记住我的密码一样?

So if you want to keep the password in the client side then put it in the cookie and if cookie already set replace the password field with cookie value.

因此,如果您想将密码保留在客户端,则将其放入 cookie 中,如果 cookie 已设置,请将密码字段替换为 cookie 值。