jQuery的改变输入类型 [英] jQuery change input type
问题描述
试图改变输入
键入从密码
到文本$ C $属性C>。
$('.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屋!