我正在尝试在<th
>中制作一个glyphicon,以指示您是按升序还是降序对值进行排序。显示的原始字形为“ glyphicon-menu-up”。
<table class="table ws-table-list table-hover">
<thead class="hidden-sm hidden-xs">
<tr>
<th class='hidden-sm hidden-xs'>
<span class="glyphicon glyphicon-menu-up"></span>
@Ajax.ActionLink("Amount", Model.PagedData.ActionMethod, new { pageNumber = Model.Number + 1, sortColumn = "amount", sortAscending = Model.PagedData.SortAscending, previousSortColumn = Model.PagedData.PreviousSortColumn }, new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = Model.PagedData.UpdateTargetId
})
</th>
</tr>
</thead>
...
</table>
我已经启用了jQuery on('click')函数(更改为“ glyphicon-menu-down”),但是它只能工作一次。不仅如此,而且在对数据进行排序后,glyphicon会自动在约0.5秒后自动恢复为“ glyphicon-menu-up”。(这与@ Ajax.ActionLink函数有关吗?)
我已经尝试过在该站点上可以找到的所有答案,包括.on,.off,.delegate,e.preventDefault和以下格式:
$('.ws-table-list').on('click', 'th', function() {
console.log('click'); // This only runs once in the console
$('span', this).toggleClass('glyphicon-menu-up glyphicon-menu-down');
});
我敢肯定答案是非常简单的,但我想我还是没有。任何帮助将不胜感激。
尝试更改事件监听器的放置位置:
$('body').on('click', '.ws-table-list th', function() {
console.log('click'); // This only runs once in the console
$('span', this).toggleClass('glyphicon-menu-up glyphicon-menu-down');
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句