Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery表排序更改按列排序的颜色:_Javascript_Jquery_Html_Sorting - Fatal编程技术网

Javascript jQuery表排序更改按列排序的颜色:

Javascript jQuery表排序更改按列排序的颜色:,javascript,jquery,html,sorting,Javascript,Jquery,Html,Sorting,我使用以下html表格和jQuery函数按表格标题列对表格进行排序: //排序汇总表 $('th')。单击(函数(){ var table=$(this).parents('table').eq(0) var rows=table.find('tr:gt(0)').toArray().sort(比较器($(this.index())) this.asc=!this.asc; 如果(!this.asc){ rows=rows.reverse(); } 对于(变量i=0;i

我使用以下html表格和jQuery函数按表格标题列对表格进行排序:

//排序汇总表
$('th')。单击(函数(){
var table=$(this).parents('table').eq(0)
var rows=table.find('tr:gt(0)').toArray().sort(比较器($(this.index()))
this.asc=!this.asc;
如果(!this.asc){
rows=rows.reverse();
}
对于(变量i=0;i

没有。
学校
校园城市/州
活动名称
工单
1.
埃尔帕索大学
埃尔帕索/德克萨斯州
全面战役
#10055
2.
达拉斯大学
达拉斯/德克萨斯州
小型活动
#10056
3.
明尼苏达大学
明尼苏达州明尼阿波利斯
全面战役
#10059	

将css颜色添加到除单击的标题外的所有标题中即可。这可以通过以下方式实现:

$('th').css({'background-color' : '#808080'}); 
$('th').css({'color' : '#FFFFFF'});
$(this).css('background-color', '#6f3d3d'); //change the background color
$(this).css({'color' : '#0000FF'});    //change the font color
只需将上述代码添加到函数中:

//排序汇总表
$('th')。单击(函数(){
//添加你的css技巧
$('th').css({'background-color':'#808080'});
$('th').css({'color':'#FFFFFF'});
$(this.css('background-color','#6f3d3d');
$(this.css({'color':'#0000FF'});
var table=$(this).parents('table').eq(0)
var rows=table.find('tr:gt(0)').toArray().sort(比较器($(this.index()))
this.asc=!this.asc
如果(!this.asc){
rows=rows.reverse();
}
对于(变量i=0;i

没有。
学校
校园城市/州
活动名称
工单
1.
埃尔帕索大学
埃尔帕索/德克萨斯州
全面战役
#10055
2.
达拉斯大学
达拉斯/德克萨斯州
小型活动
#10056
3.
明尼苏达大学
明尼苏达州明尼阿波利斯
全面战役
#10059

您只需在JS中添加一个条件,该条件将检查此列当前是否为排序依据列

$('th').click(function() {
  if (!$(this).hasClass('sort-by')) {
    $('th').removeClass('sort-by');
    $(this).addClass('sort-by');
    // logic for sorting by this column
  }
});
并在CSS中添加一个简单的规则

.sort-by {
  background-color: blue; // or whatever
}