導航:首頁 > 編程語言 > js頁面實現按時間排序

js頁面實現按時間排序

發布時間:2023-07-17 11:07:12

『壹』 利用js實現獲取當前時間進行排序

你的規律我沒看懂,到點的會提上來,後面幾個又是按什麼規則排序呢
14點的時候,為什麼不是
現在14點
現在14點30分
現在13點
現在13點30分
表示把之前開頭的放到最後。。

『貳』 用JS實現排序的功能

js常用排序實現,參考代碼如下

<script>
Array.prototype.swap=function(i,j)
{
vartemp=this[i];
this[i]=this[j];
this[j]=temp;
}

Array.prototype.bubbleSort=function()
{
for(vari=this.length-1;i>0;--i)
{
for(varj=0;j<i;++j)
{
if(this[j]>this[j+1])this.swap(j,j+1);
}
}
}

Array.prototype.selectionSort=function()
{
for(vari=0;i<this.length;++i)
{
varindex=i;
for(varj=i+1;j<this.length;++j)
{
if(this[j]<this[index])index=j;
}
this.swap(i,index);
}
}

Array.prototype.insertionSort=function()
{
for(vari=1;i<this.length;++i)
{
varj=i,value=this[i];
while(j>0&&this[j-1]>value)
{
this[j]=this[j-1];
--j;
}
this[j]=value;
}
}

Array.prototype.shellSort=function()
{
for(varstep=this.length>>1;step>0;step>>=1)
{
for(vari=0;i<step;++i)
{
for(varj=i+step;j<this.length;j+=step)
{
vark=j,value=this[j];
while(k>=step&&this[k-step]>value)
{
this[k]=this[k-step];
k-=step;
}
this[k]=value;
}
}
}
}

Array.prototype.quickSort=function(s,e)
{
if(s==null)s=0;
if(e==null)e=this.length-1;
if(s>=e)return;
this.swap((s+e)>>1,e);
varindex=s-1;
for(vari=s;i<=e;++i)
{
if(this[i]<=this[e])this.swap(i,++index);
}
this.quickSort(s,index-1);
this.quickSort(index+1,e);
}

Array.prototype.stackQuickSort=function()
{
varstack=[0,this.length-1];
while(stack.length>0)
{
vare=stack.pop(),s=stack.pop();
if(s>=e)continue;
this.swap((s+e)>>1,e);
varindex=s-1;
for(vari=s;i<=e;++i)
{
if(this[i]<=this[e])this.swap(i,++index);
}
stack.push(s,index-1,index+1,e);
}
}

Array.prototype.mergeSort=function(s,e,b)
{
if(s==null)s=0;
if(e==null)e=this.length-1;
if(b==null)b=newArray(this.length);
if(s>=e)return;
varm=(s+e)>>1;
this.mergeSort(s,m,b);
this.mergeSort(m+1,e,b);
for(vari=s,j=s,k=m+1;i<=e;++i)
{
b[i]=this[(k>e||j<=m&&this[j]<this[k])?j++:k++];
}
for(vari=s;i<=e;++i)this[i]=b[i];
}

Array.prototype.heapSort=function()
{
for(vari=1;i<this.length;++i)
{
for(varj=i,k=(j-1)>>1;k>=0;j=k,k=(k-1)>>1)
{
if(this[k]>=this[j])break;
this.swap(j,k);
}
}
for(vari=this.length-1;i>0;--i)
{
this.swap(0,i);
for(varj=0,k=(j+1)<<1;k<=i;j=k,k=(k+1)<<1)
{
if(k==i||this[k]<this[k-1])--k;
if(this[k]<=this[j])break;
this.swap(j,k);
}
}
}

functiongenerate()
{
varmax=parseInt(txtMax.value),count=parseInt(txtCount.value);
if(isNaN(max)||isNaN(count))
{
alert("個數和最大值必須是一個整數");
return;
}
vararray=[];
for(vari=0;i<count;++i)array.push(Math.round(Math.random()*max));
txtInput.value=array.join(" ");
txtOutput.value="";
}

functiondemo(type)
{
vararray=txtInput.value==""?[]:txtInput.value.replace().split(" ");
for(vari=0;i<array.length;++i)array[i]=parseInt(array[i]);
vart1=newDate();
eval("array."+type+"Sort()");
vart2=newDate();
lblTime.innerText=t2.valueOf()-t1.valueOf();
txtOutput.value=array.join(" ");
}
</script>

<bodyonload=generate()>
<tablestyle="width:100%;height:100%;font-size:12px;font-family:宋體">
<tr>
<tdalign=right>
<textareaid=txtInputreadonlystyle="width:100px;height:100%"></textarea>
</td>
<tdwidth=150align=center>
隨機數個數<inputid=txtCountvalue=500style="width:50px"><br><br>
最大隨機數<inputid=txtMaxvalue=1000style="width:50px"><br><br>
<buttononclick=generate()>重新生成</button><br><br><br><br>
耗時(毫秒):<labelid=lblTime></label><br><br><br><br>
<buttononclick=demo("bubble")>冒泡排序</button><br><br>
<buttononclick=demo("selection")>選擇排序</button><br><br>
<buttononclick=demo("insertion")>插入排序</button><br><br>
<buttononclick=demo("shell")>謝爾排序</button><br><br>
<buttononclick=demo("quick")>快速排序(遞歸)</button><br><br>
<buttononclick=demo("stackQuick")>快速排序(堆棧)</button><br><br>
<buttononclick=demo("merge")>歸並排序</button><br><br>
<buttononclick=demo("heap")>堆排序</button><br><br>
</td>
<tdalign=left>
<textareaid=txtOutputreadonlystyle="width:100px;height:100%"></textarea>
</td>
</tr>
</table>
</body>

『叄』 js 按秒排序

<!DOCTYPEHTML>
<html>
<head>
<metacharset=UTF-8/>
<title>Nothing</title>
<styletype="text/css">
</style>
<script>
varsort=function(obj)
{
vartest=document.getElementById('test');
varlis=test.getElementsByTagName('li');
vararr=[];
for(vari=0;i<lis.length;i++)
{
.push(lis[i]);
}
varflag=obj.value=='asc'?1:-1;
varreg=/-/g;
arr.sort(function(a,b)
{
vars1=newDate(a.firstChild.nodeValue.replace(reg,'/'));
vars2=newDate(b.firstChild.nodeValue.replace(reg,'/'));
if(s1>s2)
{
returnflag;
}
elseif(s1<s2)
{
return-flag;
}
else
{
return0;
}
});
obj.value=obj.value=='asc'?'desc':'asc';
for(vari=0;i<arr.length;i++)
{
test.appendChild(arr[i]);
}
}
</script>
</head>
<body>
<ulid="test">
<li>2014-11-1308:31</li>
<li>2011-11-1308:31</li>
<li>2011-1-1308:31</li>
<li>2011-3-1308:31</li>
<li>2014-11-1208:03</li>
</ul>
<inputtype="button"value="asc"onclick="sort(this);"/>
</body>
</html>

『肆』 js內容按日期排序

varss=div.innerText.split('
');
vara=[],o={};
for(vari=0;i<ss.length;i++){
vars=ss[i].split('*');
a.push(s[1]);
o[s[1]]=s[0];
}
a.sort();
a.reverse();
vars='';
for(vari=0;i<a.length;i++){
s+=o[a[i]]+'*'+a[i]+' ';
}
div.innerText=s;

『伍』 請問JSP頁面上怎麼輸出按時間排序的結果

你通過數據源(鏈接資料庫的 如HIBERNATE,IBATIS等方式)返回結果集通過你用的框架返回頁面就可以啦!
你這里說的太不具體 你用的什麼框架 什麼機制都沒說哦!

閱讀全文

與js頁面實現按時間排序相關的資料

熱點內容
如何從數控編程小白到大師 瀏覽:183
更改微信共享實時位置信息 瀏覽:13
js姓名正則 瀏覽:843
如何利用串口傳輸文件夾 瀏覽:346
jca文件怎麼用word打開 瀏覽:965
U盤文件木馬隱藏exe工具 瀏覽:152
下載優酷app視頻播放器安裝 瀏覽:38
兩個excel文件不同 瀏覽:585
如何更新網站內容 瀏覽:953
什麼網站下載廣場舞是免費的 瀏覽:307
西門子編程軟體怎麼變成中文 瀏覽:984
居客來wifi密碼 瀏覽:604
文件為何為空linux 瀏覽:630
美劇鳥app安裝包在手機哪裡 瀏覽:985
蘋果5s16g升級ios103 瀏覽:850
word紅頭文件中怎麼加雙線 瀏覽:825
切割機用什麼編程 瀏覽:787
文件修訂題目 瀏覽:572
魅族pro5自帶瀏覽器怎麼升級 瀏覽:342
為什麼用數據還是載入慢 瀏覽:171

友情鏈接