国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript 表格內容排序 簡單操作示例代碼

2019-11-20 21:19:26
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

<div id="html"></div>
<script>
var listInfos = new Array();
listInfos[0] = new Array();
listInfos[0][0] = {'name':'推薦頁1','DayCount':666,'AvgTime':29872,'ErrCount':180663,'ErrorRate':'2873%','DaySystemErrorCount':0,'DaySystemrErrorRate':'0%'}
listInfos[0][1] = {'name':'推薦頁2','DayCount':593896,'AvgTime':24946,'ErrCount':222,'ErrorRate':'2%','DaySystemErrorCount':0,'DaySystemrErrorRate':'0%'}
listInfos[0][2] = {'name':'推薦頁3','DayCount':956,'AvgTime':27957,'ErrCount':111,'ErrorRate':'10%','DaySystemErrorCount':0,'DaySystemrErrorRate':'0%'}
listInfos[1] = new Array();
listInfos[1][0] = {'name':'推薦頁4','DayCount':666,'AvgTime':116,'ErrCount':180663,'ErrorRate':'2873%','DaySystemErrorCount':0,'DaySystemrErrorRate':'0%'}
listInfos[1][1] = {'name':'推薦頁5','DayCount':11,'AvgTime':222,'ErrCount':222,'ErrorRate':'2%','DaySystemErrorCount':0,'DaySystemrErrorRate':'0%'}
listInfos[1][2] = {'name':'推薦頁6','DayCount':956,'AvgTime':956,'ErrCount':111,'ErrorRate':'10%','DaySystemErrorCount':0,'DaySystemrErrorRate':'0%'}
function dateDesc(listInfos,field){
for( var i=0; i < listInfos.length ; i++ ){
for( var j = i+1 ; j < listInfos.length ; j++ ){
if( isCommaPercent(listInfos[i][field]) < isCommaPercent(listInfos[j][field]) ){
var arrayTemp = new Array();
arrayTemp = listInfos[i];
listInfos[i] = listInfos[j];
listInfos[j] = arrayTemp;
}

}
}
return listInfos;
}
function dataAsc(listInfos,field){
for( var i=0; i < listInfos.length ; i++ ){
for( var j = i+1 ; j < listInfos.length ; j++ ){
if( isCommaPercent(listInfos[i][field]) > isCommaPercent(listInfos[j][field]) ){
var arrayTemp = new Array();
arrayTemp = listInfos[i];
listInfos[i] = listInfos[j];
listInfos[j] = arrayTemp;
}

}
}
return listInfos;
}

function isCommaPercent(value){
var valueFloat;
value = value.toLocaleString();
valueFloat = ( value.indexOf(',') > 0 )? value.split(',').join(''):value;
valueFloat = (valueFloat.indexOf('%') > 0)?parseFloat(valueFloat.substr(0,valueFloat.indexOf('%'))): parseFloat(valueFloat);
return valueFloat;
}



function sortOperation(sortInfos,field,sort){
var listInfos = new Array();
if( sort == 'desc' ){
for(var i=0; i < sortInfos.length ; i++ ){
listInfos[i] = dateDesc(sortInfos[i],field);
}
}else if( sort == 'asc' ){
for(var i=0; i < sortInfos.length ; i++ ){
listInfos[i] = dataAsc(sortInfos[i],field);
}
}else{
alert('操作錯誤...');
return false;
}

var tableStrList ='';
for( var i=0; i < listInfos.length ; i++ ){
var tableStr='<h1>程序</h1>';
tableStr+= '<table width="100%" cellspacing="0" cellpadding="0" border="1" class="programTabble"><tbody><tr class="indexTableTr">';
tableStr +='<td width="16%">程序名稱</td><td width="14%">當天訪問量(次)</td><td width="14%">平均響應時間(us)</td><td width="14%">錯誤數(次)</td>';
tableStr +='<td width="14%">錯誤率(%)</td> <td width="14%">系統錯誤數(次)</td> <td width="14%">系統錯誤率(%)</td> </tr> ';
for( var j = 0 ; j < listInfos[i].length ; j++ ){
tableStr +='<tr>';
tableStr +='<td><a href="detail.php?type=programs&pid=1">'+listInfos[i][j]['name']+'</a></td>';
tableStr +='<td>'+listInfos[i][j]['DayCount']+'</td>';
tableStr +='<td>'+listInfos[i][j]['AvgTime']+'</td>';
tableStr +='<td>'+listInfos[i][j]['ErrCount']+'</td>';
tableStr +='<td>'+listInfos[i][j]['ErrorRate']+'</td>';
tableStr +='<td>'+listInfos[i][j]['DaySystemErrorCount']+'</td>';
tableStr +='<td>'+listInfos[i][j]['DaySystemrErrorRate']+'</td>';
tableStr +='</tr>';
}
tableStr +='</tbody></table>';
tableStrList += tableStr
}

document.getElementById("html").innerHTML=tableStrList;
}
sortOperation(listInfos,'DayCount','asc')
</script>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 锡林浩特市| 玛沁县| 金乡县| 固阳县| 蒲城县| 牟定县| 临猗县| 铁岭县| 江津市| 女性| 沙洋县| 舒兰市| 太保市| 瑞安市| 舞阳县| 台中市| 阜城县| 迁安市| 出国| 贺州市| 甘南县| 密云县| 临沭县| 顺平县| 林口县| 边坝县| 阳原县| 辽阳市| 丰宁| 屏东市| 南木林县| 屏南县| 营山县| 宜宾市| 沈丘县| 句容市| 客服| 临湘市| 高邑县| 太和县| 恭城|