2011-08-31 38 views
0

我有一個問題讓tr更改邊界時,它有一個嵌套的表。有人能幫我解決這個問題嗎?jQuery設置鼠標懸停的tr邊框w /嵌套表

這裏是我的表結構

<table class="SearchResults" cellpadding="0" cellspacing="0" id="tblResultsHTML"> 
<tbody> 
     <tr class="BlackHeader"> 
    <td>header here</td> 
     </tr> 
     <tr> 
    <td> 
       <table class="SearchResults" cellpadding="2" cellspacing="0" width="100%"> 
     <tbody> 
         <tr class="GroupHeader"> 
      <td>group 1</td> 
      </tr> 
         <tr> 
      <td width="75%">sub 1</td> 
          <td valign="top">sub 2</td> 
      </tr> 
      </tbody> 
       </table> 
      </td> 
    </tr> 
     <tr> 
    <td> 
       <table class="SearchResults" cellpadding="2" cellspacing="0" width="100%"> 
     <tbody> 
         <tr class="GroupHeader"> 
      <td>group 2</td> 
      </tr> 
         <tr> 
      <td width="75%">sub 1</td> 
          <td valign="top">sub 2</td> 
      </tr> 
      </tbody> 
       </table> 
      </td> 
    </tr> 
    </tbody> 
</table> 

我的jQuery的時候,我沒有嵌套的表格,其工作是這個

$('#tblResultsHTML').live("mouseover mouseout", function (event) { 
    if (event.type == "mouseover") { 
     $(this).contents('td').css({ 'border': '2px solid black', 'border-left': 'none', 'border-right': 'none' }); 
     $(this).contents('td:first').css('border-left', '2px solid black'); 
     $(this).contents('td:last').css('border-right', '2px solid black'); 
    } else { 
     $(this).contents('td').css('border', 'none'); 
    } 
}); 

我希望發生的是,包含嵌套整排當我把它懸停時,表格有一個邊框。因此,如果我將鼠標放在組1上,該行中的整個嵌套表將具有邊框。這是否有道理?

感謝

+0

你想要的單元格邊框,或行,或嵌套表? – Blazemonger

+0

我希望父表的整行有一個邊框。所以整個嵌套表格會有一個邊框。 – AndySousa

+0

這些不是一回事。僅僅因爲該行有一個單元格,並且該單元格包含一個表格,並不意味着row = cell = table。 – Blazemonger

回答

1

http://jsfiddle.net/dQgXF/2/

從外部表中刪除「SearchResult所」級,並嘗試這個JS:

$('.SearchResults').live(
    { 
     mouseover: function() { 
      $(this).parent().css({ 
       border:'2px solid black', 
      }); 
     }, 
     mouseout: function() { 
      $(this).parent().css({ 
       border:0, 
      }); 
     }, 
    }); 
+1

或更改爲'$('。SearchResults.SearchResults')'我測試過並且工作正常:) –

+0

我在jquery中遇到了異常上面的語法。這雖然工作! $('。SearchResults')。live(「mouseover mouseout」,function(event)if(event.type ==「mouseover」){(this).parent().css({ 邊框: '2px的純黑色', });} 其他 {$ (本).parent()的CSS({ 邊界:0, });} });' – AndySousa

+0

@馬克:是的,但似乎......錯了。 – Blazemonger