<!DOCTYPE>
<html>
<머리>
<meta http-equiv="Content-type" c charset="utf-8">
<title><span>정렬</span> 테이블</title>
<스타일>
*<span>{
여백</span>:<span>0px;
패딩</span>:<span>0px;
}
몸{
배경</span>:<span>#</span><span>ccc;</span><span> }
테이블{
너비</span>:<span>350px;
여백</span>:0<span> 자동;
배경</span>-색상:<span>#</span><span>eee;</span><span> }
테이블 일{
커서</span>:<span>손;
패딩</span>:5px 0<span>;
배경</span>-색상:<span>#</span><span>999;</span><span> }
테이블 td{
배경</span>-색상:<span>#</span><span>fff;</span> 글꼴 크기:<span>16px;
글꼴</span>-중량:<span>보통;
텍스트</span>-정렬:<span>가운데;
줄</span>-높이:<span>30px;
}
</span></style>
<스크립트 언어="javascript">
<span>함수</span><span> sortCells(유형){
</span><span>var</span> tbs=document.getElementsByTagName("테이블")[0<span>];
</span><span>var</span> arr=<span>[];
</span><span>var</span> arr2=<span>[];
</span><span></span>(<span>var</span> i=1;i<tbs.rows.length>){
<span>var</span> text=tbs.rows[i].cells[유형].<span>innerText;
도착</span>.<span>push(text);
arr2[텍스트]</span>=<span>i;
}
</span><span>if</span>(유형==0<span>){
arr</span>.<span>정렬</span>(<span>함수</span>(a,b){<span>return</span> a-<span>b});
}</span><span>그밖에</span><span>{
도착</span>.<span>정렬</span><span>();
}
</span><span>var</span> temp=""<span>;
</span><span></span>(<span>var</span> j=1;j<tbs.rows.length;j <span>){
임시</span>=tbs.rows[j].cells[0].<span>innerText;
tbs</span>.rows[j].cells[0].innerText=tbs.rows[arr2[arr[j-1]]].cells[0].<span>innerText;
tbs</span>.rows[arr2[arr[j-1]]].cells[0].innerText=<span>temp;
임시</span>=tbs.rows[j].cells[1].<span>innerText;
tbs</span>.rows[j].cells[1].innerText=tbs.rows[arr2[arr[j-1]]].cells[1].<span>innerText;
tbs</span>.rows[arr2[arr[j-1]]].cells[1].innerText=<span>temp;
임시</span>=tbs.rows[j].cells[2].<span>innerText;
tbs</span>.rows[j].cells[2].innerText=tbs.rows[arr2[arr[j-1]]].cells[2].<span>innerText;
tbs</span>.rows[arr2[arr[j-1]]].cells[2].innerText=<span>temp;
</span><span>//</span><span> console.log(arr2);</span><span>for</span>(<span>var</span> i=1;i<tbs.rows.length ;나 <span>){
</span><span>var</span> text=tbs.rows[i].cells[유형].<span>innerText;
arr2[텍스트]</span>=<span>i;
}
}
}
</span></script>
</머리>
<본문>
<center><span>정렬</span> 테이블</center>
<테이블 테두리="0">
<tr>
<p>
以上就介绍了php使用js对表格进行排序, 包括了方face的内容,希望对PHP教程有兴趣的朋友有所帮助。</p>
<p>
</p></tbs.rows.length>
로그인 후 복사