quot;Show password as textquot; control(“将密码显示为文本控制)
问题描述
我有一个常用的登录表单,其中包含两个输入字段,一个用于登录,一个用于密码.我目前正在尝试添加一个控件,它将输入的密码显示为纯文本,以便用户可以检查它是否有错别字.
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.
问题是浏览器(至少是 Firefox)不允许动态更改输入字段的 type
属性,所以我不能只将 type="password"
更改为type="text"
.另一个问题是浏览器不允许获取密码字段的值,所以我不能创建一个新的 input type="text"
并将其值设置为密码的值.我见过几种不同的方法来完成这项任务,包括 这个,但它们只有在输入密码时才能工作,并且在浏览器自动填充密码时失败.
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
这篇关于“将密码显示为文本"控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“将密码显示为文本"控制


- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01