[英]Uncaught ReferenceError on jQuery script
When I try to run this script当我尝试运行这个脚本时
window.onpopstate = function(popEvent) {
let urlPath = window.location.pathName;
let slash = page.lastIndexOf("/");
let page = urlPath.substr(slash+1);
let $tab;
if (page = '') {
$tab = $("#tabs .tab:first-of-type");
page = $tab.attr("href");
}
else { $tab = $("#tabs .tab[href="+CSS.escape(page)+"]") }
$tab.addClass("current").siblings().removeClass("current");
$.ajax({url: "subpages/"+page, function(html) {
$(".append").html(html);
} });
}
I'm getting the error message:我收到错误消息:
foo.js:38 Uncaught ReferenceError: Cannot access 'page' before initialization at window.onpopstate (foo.js:38:15) foo.js:38 Uncaught ReferenceError: 在 window.onpopstate 初始化之前无法访问“页面”(foo.js:38:15)
I don't really get what's the problem.我真的不明白问题出在哪里。
Could someone help me out?有人可以帮帮我吗?
This error was caused only by mistyping: page
→ urlPath
此错误仅由错误输入引起: page
→ urlPath
window.onpopstate = function(popEvent) {
let urlPath = window.location.pathName;
let slash = urlPath.lastIndexOf("/"); // HERE
let page = urlPath.substr(slash+1);
let $tab;
if (page = '') {
$tab = $("#tabs .tab:first-of-type");
page = $tab.attr("href");
}
else { $tab = $("#tabs .tab[href="+CSS.escape(page)+"]") }
$tab.addClass("current").siblings().removeClass("current");
$.ajax({url: "subpages/"+page, function(html) {
$(".append").html(html);
} });
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.