jQuery更改输入类型 [英] jQuery change input type

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

问题描述

尝试将 input 类型属性从 password 更改为 text.

Trying to change input type attribute from password to text.

$('.form').find('input:password').attr({type:"text"});

为什么这不起作用?

推荐答案

你不能用 jQuery 做到这一点,它明确禁止它 因为 IE 不支持它(检查你的控制台你会看到一个错误.

You can't do this with jQuery, it explicitly forbids it because IE doesn't support it (check your console you'll see an error.

如果这是您所追求的,您必须删除输入并创建一个新输入,例如:

You have to remove the input and create a new one if that's what you're after, for example:

$('.form').find('input:password').each(function() {
   $("<input type='text' />").attr({ name: this.name, value: this.value }).insertBefore(this);
}).remove();

你可以在这里试试

为了明确限制,jQuery 将不允许在

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