您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用jQuery更改输入字段的类型

使用jQuery更改输入字段的类型

很可能在浏览器的安全模型中阻止了此操作。

编辑:确实,现在在Safari中进行测试,我得到了错误type property cannot be changed

编辑2:这似乎是jQuery的错误。使用以下简单的DOM代码就可以了:

var pass = document.createElement('input');
pass.type = 'password';
document.body.appendChild(pass);
pass.type = 'text';
pass.value = 'Password';

编辑3:直接来自jQuery来源,这似乎与IE有关(可能是bug或其安全模型的一部分,但jQuery并非特定):

// We can't allow the type property to be changed (since it causes problems in IE)
if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
    throw "type property can't be changed";
JS 2022/1/1 18:14:02 有630人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶