2017-07-07 47 views
0

我有一張表,我希望按順序(引用日期和時間)。我現在有參考日期和時間在HTML中排序表

<HTML> 
<HEAD> 
    <TITLE>Contents of /media/Audio/Backup Recordings/</TITLE> 
    <style type="text/css">filelist { visibility: hidden; }</style> 
</HEAD> 
<BODY> 
    <B>Contents of /media/Audio/Backup Recordings/</B> 
    <P /> 
    <TABLE> 
     <TR> 
      <TD>Type</TD> 
      <TD>Name</TD> 
      <TD>Size</TD> 
      <TD>Time</TD> 
      <TD>Hash</TD> 
     </TR> 
     <TR> 
      <TD>File</TD> 
      <TD> 
       <A HREF="XXXXXXXXX">Backup_Test_2017-03-14_11-22-27.mp3</A> 
      </TD> 
      <TD>646272</TD> 
      <TD>Tue Mar 14 11:23:07 2017</TD> 
      <TD>---</TD> 
     </TR> 
     <TR> 
      <TD>File</TD> 
      <TD> 
       <A HREF="XXXXXXXXX">Backup_Test_2_2017-03-13_09-15-00.mp3</A> 
      </TD> 
      <TD>14402304</TD> 
      <TD>Tue Mar 13 09:30:00 2017</TD> 
      <TD>---</TD> 
     </TR> 
    </TABLE> 
    <P /> 
    Up to 
    <A HREF="YYYYYYYYY">parent directory</A> 
    <P /> 
    <filelist bytes_available="2485193728"> 
     <directory read_only="true"> 
      <name>..</name> 
      <media_path>Audio</media_path> 
     </directory> 
     <file hidden="false"> 
      <name>Backup_Test_2017-03-14_11-22-27.mp3</name> 
      <size>646272</size> 
      <time>Tue Mar 14 11:23:07 2017</time> 
      <hash></hash> 
      <media_path>Audio/Backup Recordings/Backup_Test_2017-03-14_11-22-27.mp3</media_path> 
     </file> 
     <file hidden="false"> 
      <name>Backup_Test_2_2017-03-13_09-15-00.mp3</name> 
      <size>14402304</size> 
      <time>Tue Mar 13 09:30:00 2017</time> 
      <hash></hash> 
      <media_path>Audio/Backup Recordings/Backup_Test_2_2017-03-13_09-15-00.mp3</media_path> 
     </file> 
    </filelist> 
</BODY> 

有沒有一種方法訂購表格,使得3月13日條目(備份測試)3月14日(備份測試2)之前出現?我希望添加數百個錄音並根據日期和時間自動排序。

+0

請參閱https://stackoverflow.com/questions/11470775/using-jquery-ui-sortable-with-html-tables –

回答

0

你可以找到這個

要求:jQuery的

var rows = $('TABLE TR:nth-child(n+2)') 
rows.sort(function(a,b){ 
var a =new Date($(a).find("td:nth-child(4)").text()) 
var b =new Date($(b).find("td:nth-child(4)").text()) 

if (a>b) 
{ 
    return 1 
}else 
{ 
    return -1 
} 

}) 
$('TABLE TR:nth-child(n+2)').remove() 
$('TABLE').append(rows) 

當我發現你的第一個行頭。所以檢索,排序和追加在第一行之後。