2013-04-29 121 views
-1

我有一個表,我想改變顏色或<td>上覆選框是<td>更改TD顏色檢查

<table> 
<% for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
        { 
       %> 
       <tr> 
        <td> 
         <b> 
          <%Response.Write(Convert.ToDateTime(ds.Tables[0].Rows[i]["StartTime"].ToString()).ToString("hh:mm")); %> 
          - 
          <%Response.Write(Convert.ToDateTime(ds.Tables[0].Rows[i]["EndTime"].ToString()).ToString("hh:mm")); %></b> 
        </td> 
        <td> 
         <asp:CheckBox ID="chk" runat="server" /> 
        </td> 
        <td> 
         <asp:CheckBox ID="CheckBox1" runat="server" /> 
        </td> 
        <td> 
         <asp:CheckBox ID="CheckBox2" runat="server" /> 
        </td> 
        <td> 
         <asp:CheckBox ID="CheckBox3" runat="server" /> 
        </td> 
        <td> 
         <asp:CheckBox ID="CheckBox4" runat="server" /> 
        </td> 
        <td> 
         <asp:CheckBox ID="CheckBox5" runat="server" /> 
        </td> 
        <td> 
         <asp:CheckBox ID="CheckBox6" runat="server" /> 
        </td> 
       </tr> 
       <% 
        } %> 
      </table> 
+0

變化TD上選中複選框的顏色 – 2013-04-29 07:38:28

回答

2

JS小提琴:http://jsfiddle.net/satpalsingh/KPXrU/

HTML:

<table> 
    <tr> 
     <td><input type="checkbox" /></td> 
     <td><input type="checkbox" /></td> 
     <td><input type="checkbox" /></td> 
    </tr> 
</table> 

JS:

$(function(){ 
    $("input[type=checkbox]").on("change", function(){ 
     if($(this).is(':checked')) 
      $(this).parent().css('background-color', '#cd0000'); 
     else 
      $(this).parent().css('background-color', ''); 
    }); 
}); 
0

是這樣的嗎?

$('[id^="CheckBox"]').on('change',function(){ 
    if($(this).is(':checked')){ 
     $(this).parent().css('background','red'); 
    }else{ 
     $(this).parent().css('background',''); 
    } 
}); 
0

在這裏,你去。還應該在所有的IE工作:

(function($){ 

    $(function() { 
     var _ie = /msie\s[6789]/gi.test(window.navigator.userAgent), 
      _event = _ie ? 'propertychange' : 'change'; 

     $('td').each(function() { 
      var el = $(this), 
       input = el.find('input'); 

      input.bind(_event, function() { 
       el.css('color', '#yourcolor'); 
      }); 
     }); 
    }); 
})(jQuery);