Javascript 如何在jQuery中更改输入类型属性?
我有一个带有用户名和密码字段的登录表单。我使用占位符显示每个输入的帮助文本。它在Firefox和Chrome中运行良好,但在IE中不行,因为占位符是HTML5的输入属性。我正在编写一个自定义函数来处理IE中的占位符。在这个特定函数上,我想在jQuery中将密码字段输入类型从“password”更改为“text” 请对此提出解决方案Javascript 如何在jQuery中更改输入类型属性?,javascript,jquery,placeholder,Javascript,Jquery,Placeholder,我有一个带有用户名和密码字段的登录表单。我使用占位符显示每个输入的帮助文本。它在Firefox和Chrome中运行良好,但在IE中不行,因为占位符是HTML5的输入属性。我正在编写一个自定义函数来处理IE中的占位符。在这个特定函数上,我想在jQuery中将密码字段输入类型从“password”更改为“text” 请对此提出解决方案 $("#id").attr("type", "text"); 编辑: $(“#id”).remove(); $(“#containerOfInput”).appen
$("#id").attr("type", "text");
编辑:
$(“#id”).remove();
$(“#containerOfInput”).append(“
编辑:
$(“#id”).remove();
$(“#containerOfInput”).append(“
演示-->
演示-->
这应该可以:
$("#input_field_id").attr("type", "text");
这应该起作用:
$("#input_field_id").attr("type", "text");
像下面这样的东西应该会起作用
演示:
刚刚注意到您希望部件更改类型。您可以通过设置this.type
来完成此操作
- 为textfield设置this.type='text'
为密码字段设置this.type='password'
下面这样的东西应该可以解决这个问题 演示: 刚刚注意到您希望部件更改类型。您可以通过设置
this.type
来完成此操作
- 为textfield设置this.type='text'
- 为密码字段设置this.type='password'
$("#input_field_id").attr("type", "text");
$('#password').focus(function () {
this.type = 'password'
$(this).removeClass('placeholder').val(function () {
var val = $.trim(this.value);
return (val == 'Password')?'':this.value;
});
}).blur (function () {
$(this).val(function () {
var val = $.trim(this.value);
return (val == '')?'Password':this.value;
});
if (this.value == 'Password') {
$(this).addClass('placeholder')
this.type = 'text';
}
});