2011-10-15 66 views
0

我今天工作並決定開始使用JQUERY爲搜索網站製作切換表...但我幾乎是在前幾天開始使用javascript和jquery。沒有表格,它工作正常,但是當我添加表格時,它不會切換表格...我希望當您單擊「篩選搜索」時將表格放在下面,然後再次單擊過濾器搜索以隱藏表...任何幫助非常感謝。繼承人的代碼(我已經在頭jQuery的引用)不能正常工作errorJQuery切換...很可能很容易

<div class='filtermore'> 
    <h4><a>Filter Search</a></h4> 
    <p style="display: none" class='jquery'> 

    <table border=0 width="875"> 
     <tbody> 
      <tr> 
      <td width="164"><strong>City</strong></td> 
      <td width="176"><strong>Price</strong></td> 
      <td width="160"><strong>Features</strong></td> 
      </tr> 
      <tr> 
      <td><input type="checkbox"/> City 1</td> 
      <td><input type="checkbox"/> Cheap</td> 
      <td><input type="checkbox"/> Financing Available</td> 
      <td width="357"><input type="checkbox"/> Good for kids</td> 
      </tr> 
      <tr> 
      <td><input type="checkbox"/> City 2</td> 
      <td><input type="checkbox"/> Moderate</td> 
      <td><input type="checkbox"/> Smoking</td> 
      <td><input type="checkbox"/> Accepts Credit Cards</td> 
      </tr> 
      <tr> 
      <td><input type="checkbox"/> City 3</td> 
      <td><input type="checkbox"/> Expensive</td> 
      <td><input type="checkbox"/> Alcohol</td> 
      <td><input type="checkbox"/> Delivery</td> 
      </tr> 
     </tbody> 
    </table> 
    </p> 
<script> 
$("h4").click(function() { 
$(".jquery").toggle("slow"); 
}); 
</script> 


</div> 

回答

1

從技術上講,你是在告訴<p>標籤切換,不表。雖然你會認爲桌子會繼承<p>,但桌子在每個瀏覽器中都是破舊的,並且渲染方式不同,所以你不能指望它們注意。我會在表中添加一個ID並調用它,或者在jQuery中使用一個子選擇器(您肯定沒有在第一週瞭解到)直接定位表。事情是這樣的:

<table id="mytable"> 

$('#mytable').toggle('slow'); 

// or child selector method 
$('.jquery table').toggle('slow'); 

// or another method, more advanced, but the same idea would be 
$('.jquery :first-child').toggle('slow'); 
+0

是令人驚訝的工作謝謝......也使automatticaly所示的表是有辦法隱藏它在第一,然後當你點擊讓它出現? –

+0

是的,像你在桌子上的其他地方一樣使用CSS。將此添加到表格中: style =「display:none;」 – rncrtr

+0

非常感謝 –

相關問題