Javascript/jQuery—根据子对象中的值向父div添加自定义html属性<;a href>;与当前网页链接匹配的标记
在将当前网页的相对路径与Javascript/jQuery—根据子对象中的值向父div添加自定义html属性<;a href>;与当前网页链接匹配的标记,javascript,html,jquery,css,dom-manipulation,Javascript,Html,Jquery,Css,Dom Manipulation,在将当前网页的相对路径与 .... (许多其他部分)您可以使用类似以下内容检查window.location.pathname是否与a-href-值之一匹配 const escapedRef = window.location.pathname.replace(/["\\]/g, '\\$&'); document // or the parent-node of your list .querySelectorAll(`a[href^="${escapedRef
.... (许多其他部分)
您可以使用类似以下内容检查window.location.pathname
是否与a-href-值之一匹配
const escapedRef = window.location.pathname.replace(/["\\]/g, '\\$&');
document // or the parent-node of your list
.querySelectorAll(`a[href^="${escapedRef}"]`) // adding a startwith to match query and hash too
.forEach((node) => {
console.log(node);
node // a
.parentNode // .wizard-title
.parentNode // .wizard-label
.parentNode // .wizard-wrapper
.parentNode // .wizard-step
.setAttribute("data-wizard-state","current");
});
链接由标签保护是的,这只是为了用户界面定制,css类就是这样定义的(我使用的是一个自定义主题库)。我尝试使用传统的
和
方式,但UI看起来有很大不同,不适合我的用途。如果有更好的方法,请告诉我。回答得很好!感谢您提供此解决方案。