【问题标题】:How to change input type of an input field? [duplicate]如何更改输入字段的输入类型? [复制]
【发布时间】:2013-10-05 19:00:25
【问题描述】:

此脚本在所有没有 IE(7/8) 的主流浏览器中都能正常运行。 你能告诉我如何用 IE 来做吗?

<!DOCTYPE html>
<html>
<head>
<script>
function change()
{
document.getElementById("red").type='password';
}
</script>
</head>
<body>

<form>
What color do you prefer?<br>
<input type="text" name="colors" id="red" value="Text">
</form>

<button type="button" onclick="change()">Change input type</button>

</body>
</html>

【问题讨论】:

    标签: javascript


    【解决方案1】:

    你能告诉我如何用 IE 来做吗?

    这是不可能的。您需要有两个输入,一个可见,一个隐藏,并更改它们的可见性,而不是类型。

    【讨论】:

      【解决方案2】:

      IE(至少是旧版本)不支持在页面呈现后直接更改输入类型

      作为与 IE 相关的任何事情,没有严格的解决方案,只有 hackish 的解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-07
        • 2023-03-11
        相关资源
        最近更新 更多