首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可扩展列表-更改展开时显示的图像\关闭

可扩展列表-更改展开时显示的图像\关闭
EN

Stack Overflow用户
提问于 2017-05-28 23:41:10
回答 1查看 41关注 0票数 1

下面我使用ToggleList javascript函数提供了一系列可扩展的下拉选项卡。当选项卡关闭时,我想显示expand.png,当它打开时,我想显示close.png。现在,任何帮助都将不胜感激。

下面的代码展开\最小化下拉选项卡,但不切换png文件。

完整javascript + html:

代码语言:javascript
复制
     <script type="text/javascript">

            function ToggleList(IDS) {
              HideRange('ulist','div',IDS);  // not required unless using 'HideRange()' below

              var CState = document.getElementById(IDS);
              if (CState.style.display != "block") { CState.style.display = "block";      }
                                              else { CState.style.display = "none";   }
              // get a reference to the image contained in the <a> that was just clicked
              var img = this.getElementsByTagName('img')[0];
              // switch the graphic, if it's expand set it to collapse, otherwise expand
              img.src = img.src == "expand.png" ? "minimize.png" : "expand.png";
            }

            function HideRange(sect,elTag,IDS) {
                  var ContentObj = document.getElementById(sect);
                  var AllContentDivs = ContentObj.getElementsByTagName(elTag);

                }


                </script>


                <ul id="ulist">
                <li><a href="#expand" onclick="ToggleList('expand0')"><p><img src="expand.png"/> Subject</p></a></li>
                <div id="expand0" class="divInfo">Text</div>

                <li><a href="#expand" onclick="ToggleList('expand1')"><p><img src="expand.png"/> Subject</p></a></li>
                <div id="expand1" class="divInfo">Text</div>

                <li><a href="#expand" onclick="ToggleList('expand3')"><p><img src="expand.png"/> Subject</p></a></li>
                <div id="expand3" class="divInfo">Text</div>
                </ul>
EN

回答 1

Stack Overflow用户

发布于 2017-05-28 23:53:40

以下是实现该功能的简单方法--代码中的注释

代码语言:javascript
复制
    function ToggleList(IDS) {
      HideRange('ulist','div',IDS);  // not required unless using 'HideRange()' below
      var CState = document.getElementById(IDS);
      if (CState.style.display != "block") { CState.style.display = "block";      }
                                      else { CState.style.display = "none";   }
      // get a reference to the image contained in the <a> that was just clicked
      var img = this.getElementsByTagName('img')[0];
      // switch the graphic, if it's expand set it to collapse, otherwise expand
      img.src = img.src == "img/expand.png" ? "img/collapse.png" : "img/expand.png";
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44233023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档