使用jQuery(文本 - >密码)更改输入字段的类型 [英] Changing the type of an input field using jQuery (text -> password)

查看:86
本文介绍了使用jQuery(文本 - >密码)更改输入字段的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图改变输入类型,特别是在点击输入变更 type =textchange =password



我不知道为什么,但我不能添加选项 type =password作为输入属性。

  $('input#id_reg_pass')。removeAttr(type); #this works,type =text正在删除
$('input#id_reg_pass')。attr('type','password'); #problem,这不起作用
$(this).addClass('exampleText')。val($(this).attr('title'));

有没有类似的问题?我会很高兴为每个提示...
谢谢 解决方案

如果您使用jQuery 1.6, .prop 代替:

  $('input#id_reg_pass')。removeAttr(type); 
$('input#id_reg_pass')。prop('type','password');
$(this).addClass('exampleText')。val($(this).attr('title'));

演示: http: //jsfiddle.net/z8Rj3/


I am trying to change type of input, specifically after click into input change type="text" to change="password".

I don't know why, but I can't to add the option type="password" as attribute to input.

        $('input#id_reg_pass').removeAttr("type"); #this works, type="text" is removing
        $('input#id_reg_pass').attr('type', 'password'); #problem, this not works
        $(this).addClass('exampleText').val($(this).attr('title'));

Haven't someone similar problem? I'll glad for every hint... Thank you

解决方案

If you're using jQuery 1.6, use .prop instead:

$('input#id_reg_pass').removeAttr("type");
$('input#id_reg_pass').prop('type', 'password');
$(this).addClass('exampleText').val($(this).attr('title'));

Demo: http://jsfiddle.net/z8Rj3/

这篇关于使用jQuery(文本 - >密码)更改输入字段的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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