如何将类名(列表)替换为 Javascript?我有这个代码:
document.addEventListener("DOMContentLoaded", (e) => {
const url = window.location;
let urlReq = url.href;
if(urlReq.includes('/home')){
document.getElementById('default-sidenav-menu').className.replace('sidenav-main nav-expanded nav-lock nav-collapsible sidenav-active-rounded sidenav-dark', 'sidenav-main nav-collapsed nav-collapsible sidenav-active-rounded sidenav-dark');
console.log(document.getElementById('default-sidenav-menu').className);
}
});
这是我的html:
<aside class="sidenav-main nav-expanded nav-lock nav-collapsible sidenav-active-rounded sidenav-dark" id="default-sidenav-menu">
<div class="brand-sidebar">
...
</aside>
但我仍然得到默认的 className:sidenav-main nav-expanded nav-lock nav-collapsible sidenav-active-rounded sidenav-dark当我的页面加载时。
我犯了什么错误?
慕桂英3389331
料青山看我应如是
相关分类