2011-04-28 56 views
2

我有以下HTML:使用JavaScript切换标签的onclick

<div class="bubble"> 
     <div class="content recommend" style="display: block; "> 
     <h1>Recommend to your friends</h1> 

     <div id="bubble_tabs">  
      <ul style="font-size:11px;"> 
       <li id="tab1"><a class="" href="#" onclick="switch_bubble_tab(this,'#friends_inveni');return false;">Favor</a></li> 
       <li id="tab2"><a href="#" onclick="switch_bubble_tab(this,'#friends_facebook');return false;" class="active">Facebook</a></li> 
      </ul> 
     </div> 

     <div id="friends_favor" class="friends_rec" style="display: none; "> 
       <br> 
       You currently have no friends. <a style="text-decoration:underline;" href="/Friends/Invite/">Invite friends</a> or send them a recommendation via Facebook or Email. 
     </div> 

     <div id="friends_facebook" class="friends_rec" style="display: block; "> 
      <iframe src="" style="overflow:hidden;width:350px;height:400px;"></iframe> 
     </div> 

     </div> 

</div> 

我要实现的switch_bubble_tab,使得点击选项卡时,它显示传递给函数的DIV ID。我该怎么做呢?

回答

1
function switch_bubble_tab(obj) { 
$(".friends_rec").hide(); 
$(".friends_rec").eq($(obj).parents("li").index()).show(); 
//HTML below: 
<li id="tab1"><a class="" href="#" onclick="switch_bubble_tab(this);">Favor</a></li> 
+0

这会隐藏其他div吗?所以只显示一个? – adit 2011-04-28 15:49:36

+0

哎呀,忘了。更新。 – 2011-04-28 15:52:11

+0

你知道为什么它不起作用吗? http://128.196.239.71/recommend.php – adit 2011-04-28 15:56:59