當我嘗試運行此腳本時
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);
} });
}
我收到錯誤訊息:
foo.js:38 未捕獲的 ReferenceError:在 window.onpopstate (foo.js:38:15) 初始化之前無法訪問“頁面”
我真的不明白有什么問題。
有人可以幫我嗎?
uj5u.com熱心網友回復:
此錯誤僅由錯誤輸入引起: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);
} });
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/443694.html
標籤:javascript jQuery
