Getting Target URL from jQuery-UI Tabs

前端 未结 3 1634
旧时难觅i
旧时难觅i 2021-01-06 08:37

I\'m working on a project that makes heavy use of jQuery tabs and Ajax. Loading data into the tabs is simplicity itself, but the data in the tabs needs to be filtered by a s

相关标签:
3条回答
  • 2021-01-06 08:58
    var links = $("#thetabs > ul").find("li a");
    var url = $.data(links[tabnum], 'href.tabs');
    

    tabnum is the zero based index of the tab you want the url from

    0 讨论(0)
  • 2021-01-06 09:12

    The following will write out the href's to the console.

    Demo that alerts the ajax tab href's here

    $('#tabs a').each(function() {
       var href = $.data(this, 'href.tabs');
       console.log(href);
    })
    
    0 讨论(0)
  • 2021-01-06 09:13

    You can also set the title property in the tab links.

    <div id="tabs">
        <ul>
            <li><a href="tab1.html" title="First tab contents">tab1</a></li>
            <li><a href="tab2.html" title="Second tab contents">tab2</a></li>
            <li><a href="tab3.html" title="Third tab contents">tab3</a></li>
        </ul>
    </div>
    

    With this, JQueryUI will create divs with an id based on the title, with the spaces replaced by underscores, therefore you should be able to access the divs using something like

    $("#First_tab_contents")
    

    Cheers!

    0 讨论(0)
提交回复
热议问题