如果未检测到路径名,则在<link>中添加class

问题描述

| 当window.location.pathname为NULL时,我们想在链接的第一个孩子上添加一个类 的HTML代码是
  <nav>
    <a href=\"index.php\">Home</a>
    <a href=\"company.php\">Company</a>
    <a href=\"products.php\">Products</a>
    <a href=\"technical.php\">Technical</a>
    <a href=\"services.php\">Services</a>
    <a href=\"contactus.php\">Contact Us</a>
  </nav>
网址是www.nicadpower.com/
window.location.pathname.substring(1);
除了NULL之外不会产生任何其他结果。 检测到NULL后,我们希望$(\'nav a \')第一个孩子添加class = \“ current \”
  <nav>
    <a href=\"index.php\" class=\"current\">Home</a>
    <a href=\"company.php\">Company</a>
    <a href=\"products.php\">Products</a>
    <a href=\"technical.php\">Technical</a>
    <a href=\"services.php\">Services</a>
    <a href=\"contactus.php\">Contact Us</a>
  </nav>
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)