jQuery ui 手风琴正常链接

发布于 2024-11-05 20:43:12 字数 673 浏览 3 评论 0原文

我正在使用 jQuery UI accordion()。我有 4 个标签。我想做 2 个滑动,这就是手风琴的工作方式,另外 2 个只是正常链接而不滑动。我不知道如何进行正常链接,因为手风琴需要

标记后的内容元素

<div id="test">
    <h3><a href="#">One</a></h3>
    <div>
        some text
    </div>
    <h3><a href="#">Two</a></h3>
    <div>
        some text
    </div>
    <h3><a href="whatever.html">Link</a></h3>
    <h3><a href="whatever1.html">Link</a></h3>
</div>

检查 http://jsfiddle.net/3JAkv/

I'm using jQuery UI accordion(). I have 4 tabs. I want to make 2 sliding which is the way accordion works, and the other 2 just normal links without sliding. I can't figure out how to do normal link since accordion expects an element for content after the <h3> tag

<div id="test">
    <h3><a href="#">One</a></h3>
    <div>
        some text
    </div>
    <h3><a href="#">Two</a></h3>
    <div>
        some text
    </div>
    <h3><a href="whatever.html">Link</a></h3>
    <h3><a href="whatever1.html">Link</a></h3>
</div>

Check http://jsfiddle.net/3JAkv/

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

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

发布评论

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

评论(4

那一片橙海, 2024-11-12 20:43:12

看看手风琴方法(http://jqueryui.com/demos/accordion/),我不认识任何锁定项目不可打开的东西。

为什么不直接使用

 <h3><a href="whatever.html">Link</a></h3>
<h3><a href="whatever1.html">Link</a></h3>

div 的外部并正确设置它们的样式呢?

另外,您可以为标题设置不同的选择器,这将禁用该项目。例如:我将最后两个链接更改为 h2 并将手风琴设置为使用 h3 作为标题:

$('#test').accordion({ header: 'h3' })

<h2><a href="whatever.html">Three</a></h2>
<h2><a href="whatever1.html">Four</a></h2>

可以在这里看到它: http://jsfiddle.net/3JAkv/5/

你仍然需要用 CSS 来给它换肤

Looking at the accordion methods(http://jqueryui.com/demos/accordion/), I don't recognize anything for locking an item unopenable.

Why don't you just take the

 <h3><a href="whatever.html">Link</a></h3>
<h3><a href="whatever1.html">Link</a></h3>

outside of the <div id="test"> div and just style them properly?

Also, you could have a different selector for header, which will disable the item. For example: i changed the last two links to h2 and set the accordion to use h3 as header:

$('#test').accordion({ header: 'h3' })

and

<h2><a href="whatever.html">Three</a></h2>
<h2><a href="whatever1.html">Four</a></h2>

you can see it here: http://jsfiddle.net/3JAkv/5/

you still have to skin it with CSS though

暮倦 2024-11-12 20:43:12

您可以通过 jquery 更改最后 2 个选项卡的点击:

$('h3 span').slice(2) // accordion adds a span to put the triangle icon
                      // deactivate the click on it
                      // slice(2) to take last 2 tabs
            .click(function(){
    return false;     // deactivate the click
});

$('h3 a').slice(2).click(function(){
    location.href = $(this).attr('href'); // redirect the page to
                                          // the href of current anchor
    return false;                         // deactivate the click
});

jsfiddle: http ://jsfiddle.net/3JAkv/7/

You can alter the click on the last 2 tabs via jquery:

$('h3 span').slice(2) // accordion adds a span to put the triangle icon
                      // deactivate the click on it
                      // slice(2) to take last 2 tabs
            .click(function(){
    return false;     // deactivate the click
});

$('h3 a').slice(2).click(function(){
    location.href = $(this).attr('href'); // redirect the page to
                                          // the href of current anchor
    return false;                         // deactivate the click
});

jsfiddle: http://jsfiddle.net/3JAkv/7/

稀香 2024-11-12 20:43:12

我花了几天时间但终于找到了答案。

按照文档中的建议构建手风琴,并在标题下方使用没有子条目的空 div。那么就需要这两个函数。

//make links work in accordion headers
$("#accordion h3 a").click(function() {
    window.location = "default.html"+$(this).attr('href');
    window.location.reload();
    return false;
});

//cycle through each header, checking if the next div has html and remove ui-icon class if it doesn't
$("#accordion h3").each(function(index) {
    if ($(this).next("div").html() == "") {
        $(this).children("span").removeClass("ui-icon");
    }
});

Took me a couple of days but I finally found an answer.

Build out your accordion as suggested in the documentation with empty divs below your headings that don't have sub entries. Then you need these two functions.

//make links work in accordion headers
$("#accordion h3 a").click(function() {
    window.location = "default.html"+$(this).attr('href');
    window.location.reload();
    return false;
});

//cycle through each header, checking if the next div has html and remove ui-icon class if it doesn't
$("#accordion h3").each(function(index) {
    if ($(this).next("div").html() == "") {
        $(this).children("span").removeClass("ui-icon");
    }
});
断桥再见 2024-11-12 20:43:12

我认为你应该从手风琴中取出链接:

<div id="textParent">
    <div id="test">
        <h3><a href="#">One</a></h3>
        <div>
            Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        </div>
        <h3><a href="#">Two</a></h3>
        <div>
            Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        </div>
    </div>
    <h3><a href="whatever.html">Three</a></h3>
    <h3><a href="whatever1.html">Four</a></h3>
</div>

希望这会有所帮助。干杯

I think you should take the links out of the accordion:

<div id="textParent">
    <div id="test">
        <h3><a href="#">One</a></h3>
        <div>
            Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        </div>
        <h3><a href="#">Two</a></h3>
        <div>
            Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        </div>
    </div>
    <h3><a href="whatever.html">Three</a></h3>
    <h3><a href="whatever1.html">Four</a></h3>
</div>

Hope this helps. Cheers

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