【问题标题】:Jquery Slidetoggle multiple sliding divsJquery Slidetoggle 多个滑动 div
【发布时间】:2012-03-27 22:47:59
【问题描述】:

我已经浏览了一段时间,但我仍在寻找相关答案。我希望我的隐藏的 div 都是相同的类来滑动切换,但是当一个滑动另一个打开时关闭。此外,我希望仅更改正在切换的 div 的显示信息/隐藏信息。

这是我的html

<p>
    <a class="opener" href="javascript:slideTogle();">Click Here For Information</a>
</p>
<div class="content">
    <p>If you are looking to purchase your first home, reduce your existing monthly
        repayments, pay off you mortgage early, raise cash for home improvements
        or to pay off debt or even buy a property to let out we are able to assist
        and advise you from start to finish. We have access to a wide range of
        lenders offering independent mortgages to suit you.</p>
    <p>Your home may be repossessed if you do not keep up repayments on your
        mortgage.</p>
    <ul>
        <li>First time Buyers</li>
        <li>Remortgages</li>
        <li>Capital raising</li>
        <li>Debt Consolidation</li>
        <li>Buy To Let</li>
    </ul>
</div>

这是我的 javascript

$(document).ready(function () {
    // put all your jQuery goodness in here.
    $('.content').hide();
    $('.content.open').show();

    $('.opener').click(function () {


        $(this).parent().next('.content').slideToggle(300, function () {
            $(".opener").text($(this).is(':visible') ? "Hide Information" : "Click Here For Information");
        });
    });
});

我是 jquery/javascript 的新手,但我对 php 有基本的了解,并且对 html/css 有很好的了解。

谢谢

【问题讨论】:

  • $(document).ready(function() { // 把你所有的 jQuery 优点都放在这里 var showText='点击查看更多信息 ►'; var hideText='隐藏信息 9660'; $('.content.open').show(); $('.opener').click(function() { $(this).parent().next('.content').slideToggle( 'slow'); // 切换可见性 $(this).data('is_visible', !$(this).data('is_visible')); // 根据元素是显示还是隐藏来改变链接 $( this).html( (!$(this).data('is_visible')) ? showText : hideText); $('.parent, .child').hide(); });});

标签: javascript jquery show-hide slidetoggle


【解决方案1】:

喜欢this

$(document).ready(function () {
    // put all your jQuery goodness in here.

    $('.opener').click(function (e) {
        var $opener = $(this);
        var $content = $opener.parent().next('.content');        

        e.preventDefault();

        $content.toggleClass('open').slideToggle(300, function(){
            $opener.text($content.hasClass('open')?"Hide Information":"Click Here For Information");
        });

    });
});​

【讨论】:

  • 我在下面的评论中粘贴了我的最新代码,现在的问题是我有多个 div,打开选定的时关闭一个
  • 我更改了代码,以便所有手风琴相互独立运行。
  • 使用此代码根本不会打开 div。感谢您的帮助。
  • 抱歉,您能否编辑您的问题以阐明您在寻找什么?我们需要知道的是 1) 页面上有什么 2) 你如何与之交互 3) 期望的结果是什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-12
  • 2013-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多