开发者

jQuery UI Tabs - 2 Problems

开发者 https://www.devze.com 2022-12-27 12:02 出处:网络
I\'m using jQuery tabs and I\'m having some problems.Let me detail them for you here and then I\'ll put code below:

I'm using jQuery tabs and I'm having some problems. Let me detail them for you here and then I'll put code below:

PROBLEM 1:

I have a total of 6 tabs (default tab in local div, other 5 loading via Ajax). When the page loads, I need the 3rd tab to be selected by default. Easy. Problem is, say I link to http://example.com/index.html#services the 3rd tab still shows up instead of the services tab.

I've tried to use cookie to set the selected value but it just isn't working right.

PROBLEM 2:

This is major and I can't seem to figure it out. The 3rd tab is the default data and if I click on a tab to the right of that tab and come back everything is golden. BUT... If I click on a tab to the left of the 3rd tab (all tabs left or right of default are loaded via Ajax) and then click back to the 3rd tab the panel goes away completely and it's blank. Then, clicking on a different tab not only leaves the 3rd tab in a selected state (not the content just the tab itself) AND ALSO the selected tab shows in a selected state as well.

I'm pulling my hair out trying to figure out what in the world is going on here. I'll be on the road a bit today, but will check in as it's possible. Hopefully one of you can help me straighten thi开发者_如何学运维s out.

Okay... here's the code from my jquery

$(document).ready(function() {
          //build tabs
          $("#tabs").tabs( { 
              cookie: { expires : 30 },
              load: function(ui) {
                  //initilize accordion
                  $("#accordion").accordion( { active: 2 } );
              },
              show: function(event, ui) {
                  //initialize accordion
                  $("#accordion").accordion( { active : 2 } );
                  //cookie select
                  var cookie = $("#tabs").tabs("option", "cookie");
                  /*
                  if(cookie) {
                      $("#tabs").tabs("select", $.cookie('ui-tabs-1'));
                  } else {
                      $("#tabs").tabs("select", 2);
                  }
                  */
              },
              ajaxOptions: {
                  dataFilter: function(data, dataType) {
                      return $(data).find("#content_area");
                  }
              }
          } ); 

      });

Here's the code from my tabs:

<div id="tabs">
    <ul>
       <li><a href="home.html" title="home">Home</a></li>
       <li><a href="services.html" title="services">Services</a></li>
       <li><a href="#content_area">Company</a></li>
       <li><a href="employee.html" title="employee">Employee</a></li>
       <li><a href="work-tools.html" title="work_tools">Work Tools</a></li>
       <li><a href="contact.html" title="contact">Contact</a></li>
    </ul>

    <div id="content_area">
       <p>CONTENT HERE</p>
    </div>
    <!-- end #content_area -->

I sincerely appreciate your help.


Okay... Figured it out! Went in a completely new direction and actually ended up better as I can use the tabs and the back button with custom address bar changes.

I highly recommend the jQuery Address plugin as I used it to solve my problems. I had to do some tweaking with the accordion in the tabs because the autoHeight wouldn't work, but fixed that by checking the height() of accordion divs and setting changestart.

0

精彩评论

暂无评论...
验证码 换一张
取 消