首页 > 解决方案 > 为什么我的 if 和 else if 语句没有运行?

问题描述

与标题相同。

  const inputs =document.querySelectorAll('input');
  inputs.forEach(function(_inputs){
    _inputs.readOnly = !_inputs.readOnly;

    if(_inputs.readyOnly == false){
      _inputs.classList.remove("readOnlyItem")
      _inputs.classList.add("notReadOnly")
    }else if(_inputs.readyOnly == true){
      _inputs.classList.add("readOnlyItem")
      _inputs.classList.remove("notReadOnly")
    }
  });

据我所知,每件事似乎都是正确的,应该可以正常工作,但是 if 语句由于某种原因永远不会返回 true。

标签: if-statement

解决方案


推荐阅读