我有一张有7列的桌子。下面是HTML代码:
<table id="multiple-account-table" cellpadding="0" cellspacing="0">
<thead>
<tr class="border-class">
<th>Employee Name</th>
<th>Account Number</th>
<th>Account Name</th>
<th>Alias</th>
<th>Due Date</th>
<th>Total Due</th>
<th>Payment Amount</th>
</tr>
</thead>
</table>现在我的要求是,当我单击表标题时,特定的边框应该在底部有粗边框。当用户单击其他表头时,该边框应从先前的表头中移除,并应用于当前单击的表头。如下所示:
我编写了这个jQuery代码:
$(document).on('click', 'thead', function () {
$(this).addClass('sort-border');
});下面是排序边框的CSS类:
.sort-border {
border-bottom: 4px solid black;
}效果很好。但是,当我单击其他表标题时,先前单击的表标题的边框不会移除。有什么建议吗?
发布于 2016-07-20 07:16:43
如果您首先尝试删除任何标题上的类,这应该是类,那么sort-border类只有一个标头。
$(document).on('click', 'th', function () {
$('th.sort-border').removeClass('sort-border');
$(this).addClass('sort-border');
});而且,thead会将边框给整条线,如果选择th,它将仅是边框的那个单元格。
发布于 2016-07-20 07:16:44
$(document).on('click', 'thead', function () {
$('thead').removeClass('sort-border');
$(this).addClass('sort-border');
});.sort-border {
background: #ccc;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="multiple-account-table" cellpadding="0" cellspacing="0">
<thead>
<tr class="border-class">
<th>Employee Name</th>
<th>Account Number</th>
<th>Account Name</th>
<th>Alias</th>
<th>Due Date</th>
<th>Total Due</th>
<th>Payment Amount</th>
</tr>
</thead>
</table>
<table id="multiple-account-table" cellpadding="0" cellspacing="0">
<thead>
<tr class="border-class">
<th>Employee Name</th>
<th>Account Number</th>
<th>Account Name</th>
<th>Alias</th>
<th>Due Date</th>
<th>Total Due</th>
<th>Payment Amount</th>
</tr>
</thead>
</table>
发布于 2016-07-20 07:19:35
做这样的事:
$(document).ready(function(){
$('.border-class th').on('click'.function(){
$('.border-class th').removeClass('sort-border');
$(this).addClass('sort-border');
});
});https://stackoverflow.com/questions/38474622
复制相似问题