javascript - 另一个“未捕获的语法错误:意外的标识符”
问题描述
拜托,我在使用 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”并且只出现在生产环境中。
希望你能救我!
解决方案
您需要像这样使用 addEventListener
span.addEventListener("onclick", yourFunction)
否则它不起作用
推荐阅读
- javascript - 无法运行 Django-Responsive2
- arduino - 是否可以从硬件中将 arduino 恢复出厂设置以删除错误的用户代码?
- android - 如何使用屏幕限制调整文本视图?
- php - 组合数组中的每一项
- xgboost - 为什么即使默认值包含在搜索空间中,网格搜索找到的最佳参数的性能也比默认值差
- python - 为什么在我的系统上检查的工作程序上会发生此错误?关于 Tensorflow/Keras 内存管理问题
- python - 如何仅从 python 中的 Pdf 从第一个表中获取数据?
- r - 如何将 transmute 与 grep 函数结合起来?
- google-sheets - 在不同列中使用具有多个文本条件的 =averageifs
- github - 在不同的 github repo 项目中共享 Cypress 中的自定义命令