Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript/jQuery—根据子对象中的值向父div添加自定义html属性<;a href>;与当前网页链接匹配的标记_Javascript_Html_Jquery_Css_Dom Manipulation - Fatal编程技术网

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看起来有很大不同,不适合我的用途。如果有更好的方法,请告诉我。回答得很好!感谢您提供此解决方案。