开发者

trouble linking to a tab with jquery

开发者 https://www.devze.com 2023-02-13 20:59 出处:网络
im having trouble linking to a tab i have in my html either from within the same document or outside it...

im having trouble linking to a tab i have in my html either from within the same document or outside it...

here is the js code...

$(document).ready(function() {

$('.tabs a').click(function(){
    switch_tabs($(this));
});

switch_tabs($('.defaulttab'));
 });

 function switch_tabs(obj)
{
  $('.tab-content').hide();
  $('.tabs a').removeClass("selected");
  var id = obj.attr("rel");

  $('#'+id).show();
  obj.addClass("selected");
 }

and here is the way they are structured in the document...

  <ul class="tabs">
    <li><a href="#" rel="tabs2">Quickbooks</a></li>

that code makes a 'button' pulls up this tab

 <div class="tab-content" id="tabs2">
  <p>QuickBooks</p>
 </div>

what i want to do is use a href like this

   <a href="quickbooks.html#tabs2">Quickbooks</a>

and have it pull up th开发者_如何学编程e page and the associated tab... im having quite a bit of trouble... any suggestions?


Check the location.hash property in your ready handler:

if (location.hash.length > 1) {
    var tab = $('a[rel="' + location.hash.substring(1) + '"]');
    if (tab.length)
        switch_tabs(tab);
}
0

精彩评论

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