数码资讯
js报头排序实现方法
本文介绍了JS头排序的实现,供大家分享,供大家参考。 具体实现方法如下: 复制代码代码如下所示: 以降序排列 var =真正不断下滑; / ***************************************** *要排序的行必须放在标签中。 * ID:分类形式的ID *了:那是列数,排名
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
本文介绍了JS头排序的实现,供大家分享,供大家参考。
具体实现方法如下:
复制代码代码如下所示:
以降序排列
var =真正不断下滑;
/ *****************************************
*要排序的行必须放在标签中。
* ID:分类形式的ID
*了:那是列数,排名,列数,从0
* startrowno:这种起跑线数,从0开始
* sortlength:要排序的行数,
*类型:已排序列的类型
* /
功能分类(ID,了,startrowno,sortlength,型)
{
如果您想对行进行排序,则行数为1或0,则不是排序操作。
如果(sortlength <= 1){
返回;
}
无功currtable = document.getelementbyid(ID);
VaR currtable.outerhtml.substring头=(0,currtable.outerhtml.indexof(' ')+ 7)
无功thefooter = currtable.outerhtml.substring(currtable.outerhtml.indexof('')- 8);
下面是行数/删除头标题行和表列行号。
VaR排=新的数组(sortlength);
表/循环中的数据
对(我= startrowno;我< sortlength + startrowno;i++)
{
{ } =新排i-startrowno阵列(currtable。行{ } { }。细胞了。innertext.tolowercase(),currtable。行{我}。outerhtml);
}
如果(type.touppercase()= =数)
{
therows.sort(comparenumber);
}
如果(type.touppercase()= = 'date)
therows.sort(comparedate);
如果(type.touppercase()= = 'String')
therows.sort(comparestring);
无功tableinfo =
为(J = 0;J < therows.length;j++)
{
tableinfo + =排{,} { 1 };
}
不断下滑的=!不断下滑;
currtable。outerHTML =头+ tableinfo + thefooter;
返回;
}
数字/比较
功能comparenumber(x,y)
{
用于货币转换的数据格式
A = X { 0 }。excludechars(
B = y { 0 }。excludechars(
如果(= =){ = 0;}
如果(b =){ = 0;}
如果(不断下滑)
{
返回parseFloat(B)- parseFloat(一);
}
其他的
{
(一)-返回parseFloat parseFloat(B);
}
}
/ /比较字符串
功能comparestring(x,y)
{
如果(不断下滑)
{
如果(x { 0 } { y 0 })返回- 1;
否则如果(x { 0 } { 0 })返回1;
否则返回0;
}
其他的
{
如果(x { 0 } { 0 })返回- 1;
否则如果(x { 0 } { { 0 })返回1;
否则返回0;
}
}
比较时间
功能comparedate(x,y){
var arr = x { 0 }。分裂();
VaR StartTime =新的日期(ARR { 0 },ARR { 1 },ARR { 2 });
无功starttimes = starttime.gettime();
VaR方法= y { 0 }。分裂();
无功lktime =新的日期(ARRS { 0 },{ 1 }方法,ARRS { 2 });
无功lktimes = lktime.gettime();
如果(不断下滑)
{
返回lktimes - starttimes;
}
其他的
{
返回starttimes - lktimes;
}
}
/删除字符串中的所有指定字符串
string.prototype.excludechars =函数(字符){
var =新的正则表达式匹配(字符,G);
返回this.replace(匹配);
}
希望本文能对大家的javascript程序设计有所帮助。
具体实现方法如下:
复制代码代码如下所示:
以降序排列
var =真正不断下滑;
/ *****************************************
*要排序的行必须放在标签中。
* ID:分类形式的ID
*了:那是列数,排名,列数,从0
* startrowno:这种起跑线数,从0开始
* sortlength:要排序的行数,
*类型:已排序列的类型
* /
功能分类(ID,了,startrowno,sortlength,型)
{
如果您想对行进行排序,则行数为1或0,则不是排序操作。
如果(sortlength <= 1){
返回;
}
无功currtable = document.getelementbyid(ID);
VaR currtable.outerhtml.substring头=(0,currtable.outerhtml.indexof(' ')+ 7)
无功thefooter = currtable.outerhtml.substring(currtable.outerhtml.indexof('')- 8);
下面是行数/删除头标题行和表列行号。
VaR排=新的数组(sortlength);
表/循环中的数据
对(我= startrowno;我< sortlength + startrowno;i++)
{
{ } =新排i-startrowno阵列(currtable。行{ } { }。细胞了。innertext.tolowercase(),currtable。行{我}。outerhtml);
}
如果(type.touppercase()= =数)
{
therows.sort(comparenumber);
}
如果(type.touppercase()= = 'date)
therows.sort(comparedate);
如果(type.touppercase()= = 'String')
therows.sort(comparestring);
无功tableinfo =
为(J = 0;J < therows.length;j++)
{
tableinfo + =排{,} { 1 };
}
不断下滑的=!不断下滑;
currtable。outerHTML =头+ tableinfo + thefooter;
返回;
}
数字/比较
功能comparenumber(x,y)
{
用于货币转换的数据格式
A = X { 0 }。excludechars(
B = y { 0 }。excludechars(
如果(= =){ = 0;}
如果(b =){ = 0;}
如果(不断下滑)
{
返回parseFloat(B)- parseFloat(一);
}
其他的
{
(一)-返回parseFloat parseFloat(B);
}
}
/ /比较字符串
功能comparestring(x,y)
{
如果(不断下滑)
{
如果(x { 0 } { y 0 })返回- 1;
否则如果(x { 0 } { 0 })返回1;
否则返回0;
}
其他的
{
如果(x { 0 } { 0 })返回- 1;
否则如果(x { 0 } { { 0 })返回1;
否则返回0;
}
}
比较时间
功能comparedate(x,y){
var arr = x { 0 }。分裂();
VaR StartTime =新的日期(ARR { 0 },ARR { 1 },ARR { 2 });
无功starttimes = starttime.gettime();
VaR方法= y { 0 }。分裂();
无功lktime =新的日期(ARRS { 0 },{ 1 }方法,ARRS { 2 });
无功lktimes = lktime.gettime();
如果(不断下滑)
{
返回lktimes - starttimes;
}
其他的
{
返回starttimes - lktimes;
}
}
/删除字符串中的所有指定字符串
string.prototype.excludechars =函数(字符){
var =新的正则表达式匹配(字符,G);
返回this.replace(匹配);
}
希望本文能对大家的javascript程序设计有所帮助。
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。