2012-02-23 100 views
1

我有以下HTML:HTML中的交替行顏色?

<table id="ChatTable" class="ChatBox" style="margin-left:0px !important"> 
      <tr> 
      <td> 
       <table class="PopupInnerContent"> 
        <tr> 
         <td>Are you guys open today? What is your return policy?</td> 
        </tr> 
       </table> 
       </td> 
      </tr> 
      <tr> 
       <td> 
       <table class="PopupInnerContent"> 
        <tr> 
         <td>Hi yes we are open today. Out return policy is 7 days with original receipt.</td> 
        </tr> 
       </table> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="2"> 
        <textarea class="mediumResolution required"></textarea> 
       </td> 
      </tr> 
     </table> 

我具有以下的JQuery施加 :

<script> 
     $(document).ready(function() { 
      $(".ChatBox tr:even").css("background-color", "#EAEAEA"); 
      $(".ChatBox tr:odd").css("background-color", "Blue"); 
     }); 
    </script> 

問題是,應用上述的Jquery之後。 tr包含innerTable也會受此Jquery影響:我如何防止在InnerTable的Tr中影響顏色?

回答

0

試試這個:

<script> 
    $(document).ready(function() { 
     $(".ChatBox > tr:even").css("background-color", "#EAEAEA"); 
     $(".ChatBox > tr:odd").css("background-color", "Blue"); 
    }); 
</script> 

只適用於.chatbox

+0

謝謝你回答B它不工作 – 2012-02-23 12:07:13

+0

你確定內表沒有背景設置?如果風格設置正確,你可以檢查螢火蟲嗎? – 2012-02-23 12:09:16

+0

是的,即使我刪除innerTable的類名和應用>在JQuery中,它從表中刪除所有背景顏色 – 2012-02-23 12:12:46

1
$(".ChatBox > tr:pseudoclass") 

使用直接孩子>在這兩者之間FOR進入兒童

0

試試這個,

$(document).ready(function() { 
    $('.ChatBox > tbody > tr:odd').css("background-color", "Blue"); 
    $('.ChatBox > tbody > tr:even').css("background-color", "#EAEAEA"); 

});