拜托,我在使用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:意外的标识符”,仅出现在生产环境中。希望你能救我!
最佳答案
您需要使用addEventListener
像这样span.addEventListener("onclick", yourFunction)
否则不起作用
关于javascript - 另一个 “Uncaught SyntaxError: Unexpected identifier”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63379439/