我制作了一个类似手风琴的小脚本。从技术上讲,它可以工作,但在第二次点击时。如何解决?
<ul>
<li>chapter 1</li><span>lorem ipsum</span>
<li>chapter 2</li><span>lorem ipsum</span>
<li>chapter 3</li><span>lorem ipsum</span>
<li>chapter 4</li><span>lorem ipsum</span>
<li>chapter 5</li><span>lorem ipsum</span>
</ul>
var a = document.getElementsByTagName('li');
for (var i = 0; i < a.length; i++) {
a[i].onclick = function() {
var st = this.nextSibling.style;
if (st) {
st.display = (st.display == "none" ? "block" : "none");
}
};
}