jQuery 将输入类型文本转换为密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18539052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transform input type text to password
提问by user2501504
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.
我尝试使用 jQuery 函数attr
在click
事件上更改此设置,但没有任何反应。
Is this the right way to do it or is this possible?
这是正确的方法还是可能的?
回答by 26ph19
回答by trrrrrrm
jquery.Attr
should work the way that you want:
jquery.Attr
应该按照您想要的方式工作:
UPDATE
更新
This one when you click on it:
当你点击它时: