Automatically close all the other
tags after opening a specific
tag

前端 未结 6 517
日久生厌
日久生厌 2021-02-06 01:08

Here is my code.



        
6条回答
  •  无人及你
    2021-02-06 01:29

    Modification for use with polyfill jquery-details.js [Edge]

      var isIE = /*@cc_on!@*/false || !!document.documentMode;
      var isEdge = !isIE && !!window.StyleMedia;
      const details = Array.from(document.querySelectorAll("details"));
      details.forEach((targetDetail) => {
        targetDetail.addEventListener("click", () => {
          details.forEach((detail) => {
            if (detail !== targetDetail) {
              if(isEdge) {
                detail.className = detail.className.replace(/\bopen\b/g,"");
                detail.open =  false;
                detail.querySelector("summary").setAttribute("aria-expanded","false");
                var chil = detail.querySelectorAll("details > *");
                for(var j = 0; j < chil.length; j++) {
                  if(chil[j].tagName != "SUMMARY") {
                    chil[j].style.display = "none";
                  }
                }
              } else {
                detail.removeAttribute("open");
              }
            }
          });
        });
      });**strong text**
    

提交回复
热议问题