日期:2014-05-17  浏览次数:21052 次

新手求教JS给tr行添加字体颜色
 $(function ($) { 
//行颜色效果
$('.all_cont tr').hover(
function () {
        $(this).children().css('background-color', '#ffff00');
},
function () {
        $(this).children().css('background-color', '#fff');
});
  });
以上是改变行背景的颜色,现在我需要在这个前提下,再改变行的字体颜色,怎么做?
 并且,字体只在td标签里面变色,如果字体在TH标签里面的话,则无任何改变。
------解决方案--------------------
$(function ($) { 
    //行颜色效果
    $('.all_cont tr').hover(
    function () {
        $(this).children().css('background-color', '#ffff00');
        $(this).find("td").css('color', 'red');
            
    },
    function () {
        $(this).children().css('background-color', '#fff');
         $(this).find("td").css('color', 'black');          
    });
  });

------解决方案--------------------
th 外
$('.all_cont tr:has(td)').hover(
    function () {
        $(this).children().css('background-color', '#ffff00');
        $(this).find("td").css('color', 'red');
            
    },
    function () {
        $(this).children().css('background-color', '#fff');
         $(this).find("td").css('color', 'black');          
    });