【发布时间】:2018-08-13 02:37:04
【问题描述】:
我有一个包含 10 列的表头。在这些列中的每一列中都有一些文本和一个 div。 div 的目的是获得一个箭头图像,指示表格是升序还是降序。
现在,当用户单击 th 时,我希望 jQuery 将 .headerSortUp 类添加到 THAT th 内的 div 中。这是我目前得到的:
HTML:(用于标题列)
<table cellspacing="0" id="open-orders" class="enhanced tablesorter">
<thead>
<tr>
<th class="persist essential"><a href="#" rel="Symbol"></a>Company
<div class="sorter"></div></th>
<th class="hidden"><a href="#" rel="grade"></a>Stock<br class="rwd"/>Grade
<div class="sorter"></div></th>
<th class="essential"><a href="#" rel="price"></a>GTC<br class="rwd" />
Price
<div class="sorter"></div></th>
<th class="optional"><a href="#" rel="buy-date"></a>Buy<br class="rwd" />
Date
<div class="sorter"></div></th>
<th class="optional"><a href="#" rel="allocation"></a>Allocation
<div class="sorter"></div></th>
<th class="optional"><a href="#" rel="quantity"></a>Share<br class="rwd" />
Quantity
<div class="sorter"></div></th>
<th class="optional"><a href="#" rel="yield"></a>Yield
<div class="sorter"></div></th>
<th class="optional"><a href="#" rel="ex-dividend"></a>Ex-<br class="rwd" />
Dividend
<div class="sorter"></div></th>
<th><a href="#" rel="cprice"></a>Current<br class="rwd" />
Price
<div class="sorter"></div></th>
<th><a href="#" rel="return"></a>Current<br class="rwd" />
Return
<div class="sorter"></div></th>
<th class="leftnote">Notes</th>
</tr>
</thead>
jQuery:
$(document).ready(function(){
$("#open-orders tr th").click(function(){
$("#open-orders tr th").removeClass("headerSortUp");
$(this).addClass("headerSortUp");
});
});
CSS:
table.tablesorter thead tr th .sorter .headerSortUp {
background-image: url("/wcmedia/asc1.gif");
background-repeat: no-repeat;
background-position: left;
}
table.tablesorter thead tr th .sorter .headerSortDown {
background-image: url("/wcmedia/desc1.gif");
background-repeat: no-repeat;
background-position: left;
}
我不明白为什么我的 jQuery 没有将类添加到 div 中。谁能指出为什么我的 jQuery 不起作用?谢谢!
【问题讨论】:
标签: javascript jquery css html-table