2012-02-27 103 views
0

什麼事的傢伙,我在這裏問我怎麼變格內容時,點擊鏈接 這裏是代碼內容的變化:jQuery的股利時,點擊LI選項

<html> 
    <div id="bigpanel"> 
    <div id="tabs"> 
    <div id="fragment-1" class="ui-tabs-panel"> </div> 
    <div id="fragment-2" class="ui-tabs-panel ui-tabs-hide"></div> 
    <div id="fragment-3" class="ui-tabs-panel ui-tabs-hide"></div> 
    <div id="fragment-4" class="ui-tabs-panel ui-tabs-hide"></div> 
    </div> 

    <div id="banerprods"> 
    <h2><a href="#"> Drinks </a> /<a href="#"> Food </a>/<a href="#"> Misc</a></h2> 
    <div id="prodsmiddle"> 
    <table width="880" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td><li class="ul-buttom ul-buttom-hide"><a href="#fragment-1">1</a></li></td> 
    <td><li class="ul-buttom ul-buttom-hide"><a href="#fragment-2">2</a></li></td> 
    <td><li class="ul-buttom ul-buttom-hide"><a href="#fragment-3">3</a></li></td> 
    <td><li class="ul-buttom ul-buttom-hide"><a href="#fragment-4">4</a></li></td> 
    </tr> 
    </table> 
    </ul>  
    </div> 
    </html> 

我已經嘗試這個辦法:

<script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script> 
     $(document).ready(function(){ 
      $(".ui-tabs-panel").hide; 
      $(".ul-buttom ul-buttom-hide").click(function() { 
      var divname= this.value; 
       $("#"+divname).show("slow").siblings().hide("slow"); 
     }); 

     }); 
    </script> " 

但沒有工作! 請幫助!

+0

錯在何處?你有任何錯誤? – 2012-02-27 19:19:34

回答

0

試試這個?

$(document).ready(function(){ 
      $(".ui-tabs-panel").hide(); 
      $(".ul-buttom.ul-buttom-hide a").click(function() { 
       var divname= $(this).attr("href"); 
       $(divname).show("slow").siblings().hide("slow"); 
      }); 
}); 
+0

Tks傢伙現在工作完美! – Lbezerra 2012-02-28 15:41:35

0

.hide也許應該.hide()

1

你必須在你的邏輯犯了一些錯誤:

$(function(){ 
    $(".ui-tabs-panel").hide();//notice the parenthesis added to `hide()` 

    //the elements you want to select are the children `a` elements of the `li` elements with both the `.ul-buttom` and the `.ul-buttom-hide` classes 
    $(".ul-buttom.ul-buttom-hide").children().click(function() { 

     //since we are getting data from the `href` attribute, we target it with `.attr('href')`, 
     //`.value` is for form inputs 
     var divname = $(this).attr('href'); 

     //since the `href` attribues already have hash marks, we don't have to add any 
     $(divname).show("slow").siblings().hide("slow"); 
    }); 
});​ 

演示:http://jsfiddle.net/jasper/XSLEw/

+0

非常好的傑士伯,清除我的一些疑惑,並且工作真的很好! 謝謝 – Lbezerra 2012-02-28 15:46:48

0

首先.hide應該是.hide()

$(".ui-tabs-panel").hide(); 

那麼對於鏈接,如果你想要用兩個類來定位元素,你必須這樣寫,沒有空間:

$(".ul-buttom.ul-buttom-hide") 

雖然我覺得你最好的目標定位標記只有一個班就足夠了:

$(".ul-buttom-hide a").click(function() { 
    var divname= $(this).attr('href'); 
    $(divname).show("slow").siblings().hide("slow"); 
});​