【问题标题】:Can anyone plz tell why error is showing in my code its a basic addeventlistener format谁能告诉我为什么错误在我的代码中显示它是基本的 addeventlistener 格式
【发布时间】:2020-08-25 11:47:46
【问题描述】:
var ash=document.querySelector("#button");

ash.addEventListener("click", backi() {
  console.log("Clicked");
  document.body.classList.add("purple");
});

VM17:4 Uncaught SyntaxError: missing ) after argument list

【问题讨论】:

    标签: dom-manipulation


    【解决方案1】:

    你定义的函数不正确:

    var ash = document.querySelector("#button");
    
    ash.addEventListener("click", function () { // You should create lambda function
                                                // with "function () {}"
      console.log("Clicked");
      document.body.classList.add("purple");
    });
    

    【讨论】:

    • 感谢 Ivan Didyk。(迟到了)
    猜你喜欢
    • 2020-02-16
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 2020-04-29
    相关资源
    最近更新 更多