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

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

问题描述

试图改变输入键入从密码文本

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

为什么不起作用?

Why this doesn't work?

推荐答案

您不能使用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将不会允许改变键入&LT;按钮&GT; &LT;输入&GT; 这样的行为是跨浏览器一致的(因为IE好好尝试一下允许的话,他们决定它是不允许随处可见)。努力当你将获得在控制台这个错误:

To be clear on the restriction, jQuery will not allow changing type on a <button> or <input> so the behavior is cross-browser consistent (since IE doens't allow it, they decided it's disallowed everywhere). When trying you'll get this error in the console:

错误: type属性不能更改

Error: type property can't be changed

这篇关于jQuery的改变输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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