4

我正在使用 jquery 手风琴(Jquery 1.9/Jquery-ui-1.10.1)。我想使用锚标记从外部页面链接到该页面。当使用锚标签时,我想在手风琴上打开一个特定的面板。例如,如果我传递一个#panel2 锚标记,我想打开并显示第二个面板。

我在手风琴页面上也有图像,这些图像也需要链接到手风琴中的特定面板。

有人能帮忙吗?

4

1 回答 1

6

尝试:

HTML:

<a class="opener" data-panel="0" href="#">Open Section 1</a>
<a class="opener" data-panel="1" href="#">Open Section 2</a>
<a class="opener" data-panel="2" href="#">Open Section 3</a>
<a class="opener" data-panel="3" href="#">Open Section 4</a>

<div id="accordion">

<h3>Section 1</h3>

    <div>
        <p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
            ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
            amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo
            ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
    </div>

<h3>Section 2</h3>

    <div>
        <p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
            purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
            velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit
            faucibus urna.</p>
    </div>

<h3>Section 3</h3>

    <div>
        <p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
            Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
            ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia
            ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.</p>
        <ul>
            <li>List item one</li>
            <li>List item two</li>
            <li>List item three</li>
        </ul>
    </div>

<h3>Section 4</h3>

    <div>
        <p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et
            malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus
            orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel
            est.</p>
        <p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
            Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
            inceptos himenaeos.</p>
    </div>
</div>

jQuery:

var $accordion = $("#accordion");

$accordion.accordion();

$(".opener").on("click", function () {
    var $this = $(this),
        toOpen = $this.data("panel");

    $accordion.accordion("option", "active", toOpen);

    return false;
});

在这里提琴

于 2013-03-11T15:46:39.177 回答