【问题标题】:Expand and Collapse展开和折叠
【发布时间】:2013-06-06 21:15:32
【问题描述】:

我正在使用以下代码展开和折叠。

<script type="text/javascript">

    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }

</script>

<a href="#" onclick="toggle_visibility('id1');" >Click here to toggle visibility of element #foo</a>

<div id="id1">This is foo</div>


<a href="#" onclick="toggle_visibility('id2');" >Click here to see wonder</a>

<div id="id2">This is foo</div>

我想要折叠时的 +(加号)图像和展开时的 -(减号)图像。 请帮我写代码。

提前致谢。

【问题讨论】:

  • 你想把这些图片放在哪里?给as?
  • 使用.innerHTML的赋值来改变元素的内容。

标签: javascript expand collapse


【解决方案1】:

你能用 jquery 做吗?请访问此fiddle

js代码:

$(document).ready(function () {

    $('#toggle-view li').click(function () {

        var text = $(this).children('div.panel');

        if (text.is(':hidden')) {
            text.slideDown('200');
            $(this).children('span').html('-');     
        } else {
            text.slideUp('200');
            $(this).children('span').html('+');     
        }

    });

});

【讨论】:

    猜你喜欢
    • 2018-12-13
    • 2012-05-15
    • 2014-02-26
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    相关资源
    最近更新 更多