【问题标题】:Another "Uncaught SyntaxError: Unexpected identifier"另一个“未捕获的语法错误:意外的标识符”
【发布时间】:2020-12-02 08:59:07
【问题描述】:

拜托,我遇到了 sntax 问题,我不知道为什么。 我的脚本是

var popup = document.getElementById("mypopup");
var span = document.getElementsByClassName("close-btn")[0];
var sticker = document.getElementsByClassName("sticker")[0];

window.onload = function() {
  popup.style.display = "inline-block";
  sticker.style.display = "none";
}

span.onclick = function() {
  popup.style.display = "none";
  sticker.style.display = "inline-block";
}

window.onclick = function(event) {
  if (event.target == popup) {
    popup.style.display = "none";
    sticker.style.display = "block";
  }
}

似乎错误就在这一行

span.onclick = function() {

控制台消息只是“Uncaught SyntaxError: Unexpected identifier”,只是出现在生产环境中。

希望你能救我!

【问题讨论】:

  • 该代码中没有语法错误。
  • 请同时添加 html & css 代码..
  • 仅供参考,使用 addEventListener

标签: javascript syntax-error production-environment


【解决方案1】:

您需要使用 addEventListener 像这样 span.addEventListener("onclick", yourFunction) 或者它不起作用

【讨论】:

    猜你喜欢
    • 2015-06-15
    • 2013-11-28
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多