手风琴代码在插入SharePoint时保持刷新

时间:2018-09-05 00:39:25

标签: sharepoint accordion

我创建了一个我想坐在SharePoint中的代码,当我在SharePoint之外测试该代码时,它不会刷新。一旦我在SharePoint中试用了代码,在单击手风琴后它将刷新。我对编码非常陌生,可以让我知道我错过了什么吗?

var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight){
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    } 
  });
}
.accordion {
    cursor: pointer;
    padding: 5px;
    width: 100%;
    border: none;
    outline: none;

}

.active, .accordion:hover {
    background-color:#f5f3f3 ;
}

.accordion:after {
    content: '\002B';
    color: none;
    font-weight: bold;
    float: left;
  }

.active:after {
    content: "\2212";
}

.panel {
    padding: 2px;
    background-color: white;
    max-height: 0;
    overflow: hidden;
    margin-left: 22px;
}
  <button class="accordion">&nbsp;&nbsp;<b>XXXXX</b></button>
<div class="panel">
<p Style="font-family:Arial; font-size:13px">XXXXX</p>
</div>

0 个答案:

没有答案