gpt4 book ai didi

javascript - 第二个输入标签 - 我如何添加?

转载 作者:行者123 更新时间:2023-12-02 19:30:01 25 4
gpt4 key购买 nike

如何将 Javascript 代码插入到第二个输入中?

<input type="checkbox" onchange="document.getElementById('pass').type = this.checked ? 'text' : 'password'"> Show password

原始代码:

document.getElementById('pass').type

好吧,工作但是..

document.getElementById('pass' 'pass2').type

第二个“pass2”如何添加?

抱歉英语不好

最佳答案

这是不可能的,只需调用 getElementById 两次,最好使用实际的事件处理函数。

function togglePasswordVisibility() {
if(this.checked) {
document.getElementById('pass').type = 'text';
document.getElementById('pass2').type = 'text';
} else {
document.getElementById('pass').type = 'password';
document.getElementById('pass2').type = 'password';
}
}

另请注意,您的代码无法在 Internet Explorer 8 及更早版本上运行(我认为这是正确的版本号),因为它会在将元素添加到文档后修复 type

关于javascript - 第二个输入标签 - 我如何添加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11601651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com