问题描述
$(document).ready(function(){$ b)我的引导表使用了下面的jquery代码$ b $('。table> tr> td')。addClass('redBg');
console.log('hg');
});
以及我试过的这个
<$ ('.cb'('redBg'));
($。$ $ $''table> tbody> tr> td')。 console.log('hg');
});
但该类不会添加到 td
标记,
这里是工作小提琴 https: 任何人都可以帮我解决这个问题吗? 如果忽略它,许多浏览器都会隐式地添加一个 这意味着 要解决该问题,您可以: 或者,您可以添加 I have used below jquery code for my bootstrap table As well as i tried this one But the class will not added to the Here is the working fiddle https://jsfiddle.net/udarazz/0vx7tjfq/ Can anyone help me to fix this issue? If you omit it, many browsers will implicitly add a It means To work around it, you can either: Working JSFiddle. As Bootstrap styles the backgrounds of even rows and hovers, you might need to make your class definition more specific than Bootstrap's built-in styles: Alternatively, you can add 这篇关于如何使用jquery在bootstrap表中添加一个类到td标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
< tbody>
容器来包装所有的表格行。您可以使用浏览器的开发人员工具/检查器对其进行验证。由此产生的结构:
< table>
< tbody>
< tr>
< td>< / td>
< / tr>
< / tbody>
< / table>
< tr>
不是更长的直接孩子< table>
和你的表> tr
选择器不再适用。
< tbody>
,并使用表> tbody> tr> td
选择器
table tr> td
table.table tr> td.redBg {
background-color:red;
}
!important
到你的CSS来覆盖:
.redBg {
background-color:red!important;
}
$(document).ready(function() {
$('.table>tr>td').addClass('redBg');
console.log('hg');
});
$(document).ready(function() {
$('.table>tbody>tr>td').addClass('redBg');
console.log('hg');
});
td
tag, <tbody>
container to wrap all table rows. You can verify it by using your browser's developer tools/inspector. The resulting structure:<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<tr>
is no longer a direct child of <table>
, and your table > tr
selector won't work anymore.<tbody>
in your markup and use table > tbody > tr > td
selector.table tr > td
table.table tr > td.redBg {
background-color: red;
}
!important
to your CSS to override:.redBg {
background-color: red !important;
}