2013-06-02 27 views
0

我有一個非常簡單的問題,有很多標記來瀏覽。我已經上傳了一個文件,其中包含所有相同的.html文件以供審覈。在這裏發佈(標記@ 1500行)太長了,但我可以給行#鍵註釋。將函數應用於同一Div的所有表與ID - jQuery顯示/隱藏

http://www.sinsysonline.com/repair/price.html

的jQuery:

<script> 
    (function() { 

     $('tr.catTr td').not('.category').hover(function() { 

      var priceSel = $(this).index(); 

      $('tr.priceRow td').eq(priceSel).addClass('price_hover'); 
      $('tr.priceRow2 td').eq(priceSel).addClass('price_hover'); 
      $('tr.catTr td:nth-child(' + (priceSel + 1) + ')').addClass('vertFilt'); 
      $(this).parent('tr').find('td.category').addClass('category_hover'); 
      $(this).parent('tr').find('td').not('.category').addClass('rowHov'); 

     }, function() { 
      var priceSel = $(this).index(); 
      $('tr.priceRow td').eq(priceSel).removeClass('price_hover'); 
      $('tr.priceRow2 td').eq(priceSel).removeClass('price_hover'); 
      $('td.vertFilt').removeClass('vertFilt'); 
      $(this).parent('tr').find('td.category').removeClass('category_hover'); 
      $(this).parent('tr').find('td').removeClass('rowHov'); 
     }); 

})(); 
</script> 

這個問題似乎是我的功能專門爲垂直突出(臺式/筆記本/服務器),以及我在底部次級高亮,僅適用於關閉頁面。

讓我給我的理論此刻...

每個表都有的 '價格' 的ID: 4總,行: 348,541,735,968 。如果我把它變成一個類而不是一個ID,我的CSS將打破水平定位。

我一直的印象是,多個ID的都行下,只要只有一個是一次明顯的:例如:http://www.sinsysonline.com/repair/contact.html

這是隻有第一頁突出上的原因,降低懸停系統或其他方面正在發揮作用?

有什麼我可以在這裏修復只針對可見的表?

var priceSel = $(this).index(); 
     $('tr.priceRow td').eq(priceSel).addClass('price_hover'); 
     $('tr.priceRow2 td').eq(priceSel).addClass('price_hover'); 

又一次:

http://www.sinsysonline.com/repair/price.html

+2

這是在HTML無效,給予同樣的ID不止一個元素。 **甚至**只有其中一個元素可見時。 –

+2

你錯過了ID,一個ID是一個標識符,一個唯一的標識符,永遠不應該有多個具有相同ID的項目 – luk2302

+0

********更新: 設置每個表的類沒有工作。 這是初始加載DOM問題嗎? –

回答

0
<script> 
    (function() { 

     $('tr.catTr td').not('.category').hover(function() { 

      var priceSel = $(this).index(); 
      console.log(priceSel); 
      $(this).closest('table').find('tr.priceRow td').eq(priceSel).addClass('price_hover'); 
      $(this).closest('table').find('tr.priceRow2 td').eq(priceSel).addClass('price_hover'); 
      $('tr.catTr td:nth-child(' + (priceSel + 1) + ')').addClass('vertFilt'); 
      $(this).closest('tr').find('td.category').addClass('category_hover'); 
      $(this).closest('tr').find('td').not('.category').addClass('rowHov'); 

     }, function() { 
      var priceSel = $(this).index(); 
      $(this).closest('table').find('tr.priceRow td').eq(priceSel).removeClass('price_hover'); 
      $(this).closest('table').find('tr.priceRow2 td').eq(priceSel).removeClass('price_hover'); 
      $('td.vertFilt').removeClass('vertFilt'); 
      $(this).closest('tr').find('td.category').removeClass('category_hover'); 
      $(this).closest('tr').find('td').removeClass('rowHov'); 
     }); 

})(); 
</script> 

解決問題