第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在動(dòng)態(tài)菜單上實(shí)現(xiàn)尋路

在動(dòng)態(tài)菜單上實(shí)現(xiàn)尋路

慕桂英3389331 2022-06-09 19:26:58
我需要幫助做作業(yè)。我需要通過在動(dòng)態(tài)生成的導(dǎo)航中突出顯示活動(dòng)菜單項(xiàng)來創(chuàng)建 Wayfinder。當(dāng)單擊按鈕更改菜單項(xiàng)時(shí),我的代碼沒有響應(yīng)。這是我渲染的 HTML 和 JavaScript 代碼。var urlLink = "http://localhost/acme/products/?action=category&categoryName=Rocket";var path = urlLink.split("=").pop();console.log(path);liContainer = document.getElementById("navMenu");const navAnchor = liContainer.getElementsByClassName('mainMenu');/*navAnchor.forEach(anchor => {  anchor.addEventListener('click', addActive);});*/for (var i = 0; i < navAnchor.length; i++) {  navAnchor[i].addEventListener("click", addActive);}function addActive(e) {  var liAnchor = liContainer.target.tagName("a").getAttribute("href");  if (liAnchor.split("=").pop() === path) {    const current = document.querySelector('li.active');    current.className = current.className.replace(" active", "");    e.target.className += " active";  }}.active {  background-color: red;  color: white;  padding: 10px}<ul id="navMenu">  <li class="mainMenu active"><a href="/acme/" title="View the Acme home page">Home</a></li>  <li class="mainMenu"><a href="/acme/products/?action=category&amp;categoryName=Cannon" title="View our Cannon product line">Cannon</a></li>  <li class="mainMenu"><a href="/acme/products/?action=category&amp;categoryName=Explosive" title="View our Explosive product line">Explosive</a></li>  <li class="mainMenu"><a href="/acme/products/?action=category&amp;categoryName=Misc" title="View our Misc product line">Misc</a></li>  <li class="mainMenu"><a href="/acme/products/?action=category&amp;categoryName=Rocket" title="View our Rocket product line">Rocket</a></li>  <li class="mainMenu"><a href="/acme/products/?action=category&amp;categoryName=Trap" title="View our Trap product line">Trap</a></li></ul>
查看完整描述

1 回答

?
滄海一幻覺

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

我使用以下代碼解決了我自己的問題:


var path = window.location.href.split("=").pop();


var liContainer = document.getElementById("navMenu");

const navAnchor = liContainer.getElementsByClassName('mainMenu');


for (var i = 0; i < navAnchor.length; i++) {  

  var liAnchor = navAnchor[i].getElementsByTagName("a");

  for (var j = 0; j < liAnchor.length; j++) {

    linkPath = liAnchor[j].getAttribute("href").split("=").pop();

    if (linkPath === path) {

      var current = document.getElementsByClassName("active");

      current[0].className = current[0].className.replace(" active", "");

      navAnchor[i].className += " active";

    } 

  }

}


查看完整回答
反對(duì) 回復(fù) 2022-06-09
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)