Javascript IE6 / 7/8改变输入类型 [英] Javascript IE6/7/8 change input type

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

问题描述

以下javascript代码段将改变INPUT的类型,例如从文本到密码。它用于允许用户在输入密码时在屏幕上显示他们的密码:

The following javascript snippet will change the type of an INPUT, for instance from text to password. It's being used to allow users to display their password on-screen when typing it in:

document.save_form.password_confirm.type= 'text';
...
document.save_form.password_confirm.type= 'password';

这对FF / Chrome非常有用,但是在IE6 / 7/8中,我得到了This命令不受支持错误消息。

This works great in FF/Chrome but in IE6/7/8 I'm getting a "This command is not supported" error message.

推荐答案

类型在Internet Explorer中是只读的(至少6,无论如何),所以它不是直接可能的。作为一种解决方法,我有一个我想要的类型的隐藏输入字段,然后当我需要切换类型时,隐藏旧类型并使另一个类型可见。不是很干净,但不幸的是,只要改变类型,据我所知是不可能的。

Type is read-only in Internet Explorer (at least 6, anyway), so it's just not directly possible. As a workaround, I've had a hidden input field of the type I wanted, then when I need to switch the type, hid the old one and made the other one visible. Not as clean, but unfortunately just changing the type as far as I know isn't possible.

另一种方法是使用JavaScript DOM来替换字段节点的replaceChild功能。

An alternative method would be to use the JavaScript DOM to replace the field with the replaceChild function of a node.

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

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