Jquery手风琴,下一个和上一个向导,如何获取上一个和下一个部分?

发布于 2024-08-04 10:37:41 字数 1202 浏览 4 评论 0原文

我有一个 Jquery 手风琴,工作正常。单击相应标题时,部分会展开/折叠。但我想添加功能,以便当我单击“下一个”按钮时,它会打开下一部分,单击“上一个”按钮会将我带回上一个部分。

这已在此页面上完成 http://jquery.bassistance.de/ Accordion/demo/?p=1.1.2 (最后一个示例)但不确定如何在我的情况下实现相同的效果。

有什么建议请。

谢谢

更新:我如何获得手风琴的上一节或下一节?

<script type="text/javascript">
 $("#accordion").accordion({ 
   header: "h3.header"
   , autoHeight: false
   , collapsible: true
  });
</script>

<div id="accordion">
 <h3 class="header">Section 1</h3>
 <div> content 1 .. content 1 .. content 1 .. content 1 ..
  <input class="next" type="button" value="next"/>   
 </div>
 <h3 class="header">Section 2</h3>
 <div> content 2 .. content 2 .. content 2 .. content 2 ..
  <input class="previous" type="button" value="previous"/>
  <input class="next" type="button" value="next"/>   
 </div>
 <h3 class="header">Section 3</h3>
 <div> content 3 .. content 3 .. content 3 .. content 3 ..
  <input class="previous" type="button" value="previous"/>
 </div> 
</div>

I have a Jquery accordion which works fine. Sections get expanded/collapsed when clicked on respective headers. But I want to add the functionality so that when I click on "next" button it opens up the next section and clicking "Previous" button takes me back to previous section.

This has been done on this page http://jquery.bassistance.de/accordion/demo/?p=1.1.2 (last example) but not sure how do I implement the same in my case.

Any suggestions please.

Thanks

UPDATE: How do I get previous or next section of the accordion?

<script type="text/javascript">
 $("#accordion").accordion({ 
   header: "h3.header"
   , autoHeight: false
   , collapsible: true
  });
</script>

<div id="accordion">
 <h3 class="header">Section 1</h3>
 <div> content 1 .. content 1 .. content 1 .. content 1 ..
  <input class="next" type="button" value="next"/>   
 </div>
 <h3 class="header">Section 2</h3>
 <div> content 2 .. content 2 .. content 2 .. content 2 ..
  <input class="previous" type="button" value="previous"/>
  <input class="next" type="button" value="next"/>   
 </div>
 <h3 class="header">Section 3</h3>
 <div> content 3 .. content 3 .. content 3 .. content 3 ..
  <input class="previous" type="button" value="previous"/>
 </div> 
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

无语# 2024-08-11 10:37:41

我能够让它发挥作用。尝试一下,它适用于 jQuery 1.6 和 jQuery UI 1.8:

HTML:

<div id="checkout">
    <h2><a href="#">Section 1</a></h2>
    <div>
        <form action="#">
            <h3>Content</h3>
            <input type="submit" class="next" value="Continue" />
        </form>
    </div>
    <h2><a href="#">Section 2</a></h2>
    <div>
        <form action="#">
            <h3>Content</h3>
            <input type="submit" class="prev" value="Back" />
        </form>
    </div>
</div>

jQuery:

<script type="text/javascript">
    $(document).ready(function () {
        // create new accordion
        var checkout = $('#checkout').accordion({ event: false });

        // assign accordion navigation events to button clicks
        $('form', checkout).each(function (index) {
            $(this)
            .children(':submit')
            .filter('.next, .prev')
            .click(function () {
                checkout.accordion('option', 'active', index + ($(this).is('.next') ? 1 : -1));
                return false;
            });
        });
    });
</script>

I was able to get it to work. Give this a shot, it works with jQuery 1.6 and jQuery UI 1.8:

HTML:

<div id="checkout">
    <h2><a href="#">Section 1</a></h2>
    <div>
        <form action="#">
            <h3>Content</h3>
            <input type="submit" class="next" value="Continue" />
        </form>
    </div>
    <h2><a href="#">Section 2</a></h2>
    <div>
        <form action="#">
            <h3>Content</h3>
            <input type="submit" class="prev" value="Back" />
        </form>
    </div>
</div>

jQuery:

<script type="text/javascript">
    $(document).ready(function () {
        // create new accordion
        var checkout = $('#checkout').accordion({ event: false });

        // assign accordion navigation events to button clicks
        $('form', checkout).each(function (index) {
            $(this)
            .children(':submit')
            .filter('.next, .prev')
            .click(function () {
                checkout.accordion('option', 'active', index + ($(this).is('.next') ? 1 : -1));
                return false;
            });
        });
    });
</script>
风透绣罗衣 2024-08-11 10:37:41

将其添加到您的 jQuery 文件中。它添加了一个函数 $("#accordion").accordion("next") 和一个选项“loopOnNext”(默认 false),以强制它在结束时返回到顶部框。

$.extend($.ui.accordion.prototype, {
    next: function(){
        var index = this.option('active') || 0,
            next = index + 1,
        nodes = $(this.element).children('h3').length;
        if(next >= nodes && this.option('loopOnNext') === true) {
            next = 0;
        }

        return this.activate(next);
    }
});

Add this to your jQuery files. It adds a function $("#accordion").accordion("next") and an option, "loopOnNext" (default false) to force it to return to the top box when it's at the end.

$.extend($.ui.accordion.prototype, {
    next: function(){
        var index = this.option('active') || 0,
            next = index + 1,
        nodes = $(this.element).children('h3').length;
        if(next >= nodes && this.option('loopOnNext') === true) {
            next = 0;
        }

        return this.activate(next);
    }
});
鹿港巷口少年归 2024-08-11 10:37:41

我有一个类似的问题并使用:

<button onclick="$('#accordion').accordion('activate', 0);">Prev</button>
<button onclick="$('#accordion').accordion('activate', 2);">Next</button>

在每个手风琴窗格上。它位于第二个窗格中,可让您返回到第一个窗格(索引为 0)或前进到第三个窗格(索引为 2)。

I had a similar problem and used:

<button onclick="$('#accordion').accordion('activate', 0);">Prev</button>
<button onclick="$('#accordion').accordion('activate', 2);">Next</button>

on each accordion pane. This is on the 2nd pane and brings you back to the first (index of 0) or forward to the third (index of 2).

鲜肉鲜肉永远不皱 2024-08-11 10:37:41

您是否尝试过像示例中那样做?

var wizard = $("#accordion").accordion({ 
    header: 'h3.header', 
    event: false
}); 

$("h3.header", wizard).each(function(index) { 
    $(this) 
    .next() 
    .children(":button") 
    .filter(".next, .previous") 
    .click(function() { 
        wizard.changeAccordion("activate", index + ($(this).is(".next") ? 1 : -1)) 
    }); 
});

Have you tried to do just like in example?

var wizard = $("#accordion").accordion({ 
    header: 'h3.header', 
    event: false
}); 

$("h3.header", wizard).each(function(index) { 
    $(this) 
    .next() 
    .children(":button") 
    .filter(".next, .previous") 
    .click(function() { 
        wizard.changeAccordion("activate", index + ($(this).is(".next") ? 1 : -1)) 
    }); 
});
苄①跕圉湢 2024-08-11 10:37:41

我正在寻找同一问题的解决方案并提出了这个(我正在使用 jQuery 1.4.2 和 jQuery UI 1.8.1):

<div id="wizard">
    <h3><a href="#step1">Step 1 / 3</a></h3>
    <div id="step1">
        <button type="button">Next »</button>
    </div>
    <h3><a href="#step2">Step 2 / 3</a></h3>
    <div id="step2">
        <button type="button">Next »</button>
    </div>
    <h3><a href="#step3">Step 3 / 3</a></h3>
    <div id="step3">
        <button type="submit">Finish</button>
    </div>
</div>

这是脚本:

<script type="text/javascript">
    $(function() {

        $('#wizard').accordion();

        $('#wizard :button').each(function (index, elm) {
            $(elm).click(function() {
                $('#wizard').accordion('activate', index + 1);
            });
        });

    });
</script>

I was looking for a solution to the same problem and come up with this (I'm working with jQuery 1.4.2 and jQuery UI 1.8.1):

<div id="wizard">
    <h3><a href="#step1">Step 1 / 3</a></h3>
    <div id="step1">
        <button type="button">Next »</button>
    </div>
    <h3><a href="#step2">Step 2 / 3</a></h3>
    <div id="step2">
        <button type="button">Next »</button>
    </div>
    <h3><a href="#step3">Step 3 / 3</a></h3>
    <div id="step3">
        <button type="submit">Finish</button>
    </div>
</div>

And this is the script:

<script type="text/javascript">
    $(function() {

        $('#wizard').accordion();

        $('#wizard :button').each(function (index, elm) {
            $(elm).click(function() {
                $('#wizard').accordion('activate', index + 1);
            });
        });

    });
</script>
爱的那么颓废 2024-08-11 10:37:41

试试这个:

var wizard = $("#register_form").accordion({
    header: '.title',
    event: 'none',
    collapsible: false
});
$(':button.previous').click(function() { wizard.accordion("activate", 0); });
$(':button.next').click(function() { wizard.accordion("activate", 1); });

其中 :button 是上一个和下一个按钮,wizard 是你的 jQuery 手风琴。
省略所有其他代码。看看这是否有效。
请留下反馈,谢谢。

try this:

var wizard = $("#register_form").accordion({
    header: '.title',
    event: 'none',
    collapsible: false
});
$(':button.previous').click(function() { wizard.accordion("activate", 0); });
$(':button.next').click(function() { wizard.accordion("activate", 1); });

Where :button are the prev and next buttons, and wizard is your jQuery accordion.
Leave out all the other code. See if this works.
Please leave feedback, thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文