Transform input type text to password [duplicate]

泪湿孤枕 提交于 2019-12-22 12:38:23

问题


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');"/>

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?


回答1:


This will work

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

jsfiddle

Update

For IE read accepted answer for this post.




回答2:


jquery.Attr should work the way that you want:

http://jsfiddle.net/7UA95/

UPDATE

This one when you click on it:

http://jsfiddle.net/7UA95/1/



来源:https://stackoverflow.com/questions/18539052/transform-input-type-text-to-password

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!