将输入类型的文本转换为密码 [英] Transform input type text to password

查看:60
本文介绍了将输入类型的文本转换为密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击输入类型时将其更改为密码.我试过了:

I want to change the input type to password when I click on it. I tried this:

<input name="pin" id="cp_serv" type="text" class="pin_v" value="Insert PIN Please" onclick="this.value='';$(this).attr('type','password');"/>

我尝试使用jQuery函数attrclick事件上更改此设置,但没有任何反应.

I tried to use the jQuery function attr to change this on the click event, but nothing is happening.

这是正确的方法还是有可能?

Is this the right way to do it or is this possible?

推荐答案

这将起作用

$('input').on('click', function () {
   $(this).attr('type', 'password'); 
});

jsfiddle

jsfiddle

更新

对于IE,阅读此帖子的可接受答案.

For IE read accepted answer for this post.

这篇关于将输入类型的文本转换为密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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