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

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

问题描述

我想在点击时将输入类型更改为密码.我试过这个:

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

更新

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

For IE read accepted answer for this post.

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

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