You need to enable JavaScript to run this app. 输入正确密码后启用flex-container类及launch-button元素失效求助
优惠活动
大模型
产品
解决方案
定价
更多

输入正确密码后启用flex-container类及launch-button元素失效求助

解决方案

你原有代码的基础逻辑可正常运行,若要严格仅启用指定元素、避免误操作页面其余禁用输入项,可调整选择器精准匹配目标元素,修改后代码如下:

const password = "TrustNo1";

document.getElementById("ok-button")
        .addEventListener("click", function () {
            if (document.getElementById("password").value === password) {
                // 匹配所有flex-container下的input和launch-button按钮
                document.querySelectorAll('.flex-container input, #launch-button')
                    .forEach(el => el.disabled = false);
            }
        });

补充说明

  • 将原有判断的==替换为===为更严谨的全等判断,可规避隐式类型转换带来的异常问题
  • 若你需要实现JS自动禁用目标元素,无需手动在HTML逐个添加disabled属性,可补充页面加载初始化逻辑,解决此前JS禁用失效的问题:
// 页面DOM加载完成后自动禁用目标元素
document.addEventListener('DOMContentLoaded', () => {
  document.querySelectorAll('.flex-container input, #launch-button')
    .forEach(el => el.disabled = true);
})

内容的提问来源于stack exchange,提问作者BovineScatologist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 03:15:03