jQuery根据';副处长';内部';td';
我有一个表,其中第一行的内容在每个“td”内的两个“div”内。其余两行的内容在“td”本身中 表需要按照“排序”下拉列表中选择的参数按列进行排序(升序)。(为便于理解,“div”和相应下拉文本中的内容,已对其进行颜色编码,如下图所示) 我使用jquery对td中的第2行和第3行内容进行排序,如下所示,运行良好:jQuery根据';副处长';内部';td';,jquery,sorting,html-table,Jquery,Sorting,Html Table,我有一个表,其中第一行的内容在每个“td”内的两个“div”内。其余两行的内容在“td”本身中 表需要按照“排序”下拉列表中选择的参数按列进行排序(升序)。(为便于理解,“div”和相应下拉文本中的内容,已对其进行颜色编码,如下图所示) 我使用jquery对td中的第2行和第3行内容进行排序,如下所示,运行良好: var RowtoSort = $(".CompTable tr." + $(this).find("option:selected").text());
var RowtoSort = $(".CompTable tr." + $(this).find("option:selected").text());
RowtoSort.find('td:not(:first)').sort(function(a, b) {
a = $(a).text();
b = $(b).text();
return (a === 'NA')-(b === 'NA') || -(a>b)||+(a<b);
}).each(function(new_Index) {
var original_Index = $(this).index();
Rows.each(function() {
var td = $(this).find('td, th');
if (original_Index !== new_Index)
td.eq(original_Index).insertAfter(td.eq(new_Index));
});
});
排序方式:
统计数字1
统计数字2
参数1
参数2
三星
苹果
摩托罗拉
统计
3200
0
1500
NA
4100
1500
参数1
0
NA
7000
参数2
5000
NA
7000
使用find()
筛选表内部div
a = $(a).find(datasub)
b = $(b).find(datasub)
基于数据子项
<option name=Statistics data-sub="Statistics1" style="color: blue">Statistics1</option>
<option name=Statistics data-sub="Statistics2" style="color: red">Statistics2</option>
排序方式:
统计数字1
统计数字2
参数1
参数2
三星
苹果
摩托罗拉
统计
3200
0
1500
NA
4100
1500
参数1
0
NA
7000
参数2
5000
NA
7000
非常感谢!!学到了新东西!!:)一个问题,这是什么意思datasub:未定义代码>做什么?你怎么看这个?再次感谢,令人惊讶的回答!!:)@三尺土
<option name=Statistics data-sub="Statistics1" style="color: blue">Statistics1</option>
<option name=Statistics data-sub="Statistics2" style="color: red">Statistics2</option>