javascript - 为什么没有将类添加到加载的导航元素?
问题描述
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");
})
})
推荐阅读
- openlayers - 如何修复“错误:无法为图层创建渲染器:未定义”?
- python-3.x - python json.dumps() 并将数据插入 mysql 1064 错误
- qt - 使用带有“父项:Overlay.overlay”的弹出窗口时的 QML 属性值传播
- javascript - Ionic/Firebase 图像选择器/裁剪和上传问题
- javascript - 使用 ng-change 函数更改变量的值
- ruby-on-rails - 访问类主体中的变量
- sql - 如何在 SQL 中创建特殊情况的 Intersect 子句?
- python - 为什么在循环中调用变量后会发生变化?
- function - Haskell中不同数据类型的函数
- excel - 如何纠正范围(单元格)中的错误?