"显示密码文本"控制 [英] "Show password as text" control

查看:121
本文介绍了"显示密码文本"控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包括两个输入域,一个用于登录,一个密码的通常登录表单。目前我正在试图加入,将显示输入的密码以纯文本的控制,使用户可以检查是否有错别字。

I have a usual login form consisting of two input fields, one for login, one for password. I am currently trying to add a control that will show entered password as plain text, so user can check it for typos.

问题是,浏览器(至少火狐)不允许键入输入域的属性,所以我不能只是改变类型的动态变化=密码键入=文字。另一个问题是,浏览器不允许获得密码字段的值,所以我不能创建一个新的输入类型=文本,并将其值设置为密码的One 。我已经看到了几种不同的方法把这个任务,其中包括这个,但它们仅如果密码输入并且当浏览器自动填充密码失败工作

The problem is that browsers (at least Firefox) do not allow dynamic changing of type attribute of input fields, so I cannot just change type="password" to type="text". Another problem is that browsers do not allow to get value of password field, so I can't create a new input type="text" and set its value to the password's one. I've seen several different approaches to this task, including this one, but they are working only if the password is typed and fail when browser autofills the password.

因此​​,任何建议,要做到这一点是值得欢迎的。我使用jQuery。

So, any suggestions to do this are welcome. I am using jQuery.

推荐答案

您可以做这样的事情:

<input type="password" id="password">
<input type="checkbox" onchange="document.getElementById('password').type = this.checked ? 'text' : 'password'"> Show password

这篇关于&QUOT;显示密码文本&QUOT;控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆