我有以下代码:
<tr><td class="style3">test</td></tr>
和
$("tr").hover(
function () {
$(this).css("background-color","#d9e8cd");
$(this).css("font-weight","bold");
$(this).children().css("color","#222222 !important");
},
function () {
$(this).css("background-color","");
$(this).css("font-weight","");
$(this).children().css("color","#4b4a4a");
}
);
问题是文本颜色不会改变,我尝试指定 tr 但它不起作用所以我假设以 td 为目标会使其工作,因为指定颜色的 style3 类。
我怎样才能使鼠标悬停在 tr 上时文本的颜色发生变化?
这是一个在线演示 http://jsfiddle.net/B7dMd/
最佳答案
jQuery CSS 不支持重要语法。如果你真的需要添加 "!important"你可能想试试 CSS DOM cssText:
$(this).children().css('cssText', 'color:#222222 !important');
要指出的是 - 在大多数情况下,没有理由应该在内联样式中添加 !important,因为内联样式具有高优先级,您只需要这样做来覆盖另一个 !important规则。
关于javascript - $(this).children() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14062555/