Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择onChange在Chrome上不起作用_Javascript_Google Chrome_Select_Onchange_Mozilla - Fatal编程技术网

Javascript 选择onChange在Chrome上不起作用

Javascript 选择onChange在Chrome上不起作用,javascript,google-chrome,select,onchange,mozilla,Javascript,Google Chrome,Select,Onchange,Mozilla,我主要使用Mozilla,但现在我注意到一些代码没有在Chrome上运行,比如带有eventListener的select>option 这是页面的链接:在Chrome和Mozilla上查看 我想这部分工作也为铬。我怎样才能做到这一点 cbs = document.querySelectorAll("input[type=checkbox]"); selector = document.querySelectorAll("#selector option"); (function() {

我主要使用Mozilla,但现在我注意到一些代码没有在Chrome上运行,比如带有eventListener的select>option

这是页面的链接:在Chrome和Mozilla上查看

我想这部分工作也为铬。我怎样才能做到这一点

cbs = document.querySelectorAll("input[type=checkbox]");
selector = document.querySelectorAll("#selector option");

(function() {
  targets = document.querySelectorAll("#table tr td:nth-child(3)");
  newTr = document.querySelectorAll("#table tr");
  for (var z = 0; z < cbs.length; z++) {
    cbs[z].addEventListener("change", function() {
      targets = document.querySelectorAll("#table tr td:nth-child(3)");
      newTr = document.querySelectorAll("#table tr");
      console.log(newTr);
      console.log(targets);
    })
  }
  // DA FIXARE OPTION => CHECKBOX NEW
  for (l = 0; l < selector.length; l++) {
    selector[l].addEventListener("click", function() {
      for (var i = 0; i < targets.length; i++) {
        //console.log(i);
        newTr[i].classList.add("hide-row");
        if (targets[i].innerHTML == this.value && newTr[i].classList.contains("hide-row")) {
          //console.log("Match: " + i);
          newTr[i].classList.remove("hide-row");
        } else if (this.innerHTML === "ALL"){
          for (let i = 0; i < targets.length; i++) {
            newTr[i].classList.remove("hide-row");
          }
        }
      }
    });
  }
  for (var p = 0; p < cbs.length; p++) {
    cbs[p].addEventListener("change", function() {
      console.log("Checkbox");
    })
  }
})();
cbs=document.querySelectorAll(“输入[type=checkbox]”);
选择器=document.querySelectorAll(“选择器选项”);
(功能(){
targets=document.queryselectoral(#table tr td:nth child(3)”;
newTr=document.queryselectoral(#table tr”);
对于(var z=0;z复选框新建
对于(l=0;l
从语义上讲,我们不应该在选项标记中添加“单击”侦听器。
标记有一个“更改”事件,您可以收听该事件,然后在更改
时进行适当的更改


请参考这个。希望这有帮助。

您确定要将侦听器添加到正确的输入中吗?在您的问题中,您编写了
select>选项
,但您正在将它们添加到
input[type=checkbox]
。是的,我在Chrome中看到了预期的效果(控制台登录复选框更改)是的,但我说的是选择>选项。看来我用错语法了是的,你说得对!我将以这种方式重新制作它!非常感谢你!