this.loadTemplate = async(currentPage) => {
let promise = new Promise((resolve) => {
$(() => $("#nav").load("./nav.html"));
$(() => $("#footer").load("./footer.html"));
resolve("resolved");
});
let result = await promise;
console.log(result);
$(`#${currentPage}`).addClass("current-page");
};
以上是加载类并将其添加到 nav.html 文件的代码。这应该将元素更改为橙色。 它没有。
感谢任何帮助。
最佳答案
为什么不让 jQuery 完成这项工作或者不使用 jQuery
let currentPage = "someId";
$("#nav").load("./nav.html", function() {
$("#footer").load("./footer.html", function() {
$("#" + currentPage).addClass("current-page");
})
})
关于javascript - 为什么不将类添加到已加载的导航元素中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59570057/