php使用js對表格進行排序

WBOY
發布: 2016-07-29 09:15:28
原創
1110 人瀏覽過



    <meta http-equiv="Content-type" c charset="utf-8">
    <span>排序</span>表格
    
        *<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> }
        表th{
            遊標</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>風格>
    
        <span>函數</span><span>sortCells(類型){
            </span><span>var</span> tbs=document.getElementsByTagName("table")[0<span>];
            </span><span>var</span> arr=<span>[];
            </span><span>var</span> arr2=<span>[];
            </span><span>for</span>(<span>var</span> i=1;i<tbs.rows.length>){
                <span>var</span> text=tbs.rows[i].cells[type].<span>innerText;
                arr</span>.<span>push(text);
                arr2[文本]</span>=<span>i;
            }
            </span><span>if</span>(型==0<span>){
                arr</span>.<span>排序</span>(<span>函數</span>(a,b){<span>回傳</span> a-<span>b});
            }</span><span>否則</span><span>{
                arr</span>.<span>排序</span><span>();
            }
            </span><span>var</span> temp=""<span>;

            </span><span>for</span>(<span>var</span> j=1;j<tbs.rows.length>){
                temp=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;

                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;

                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>var</span> text=tbs.rows[i].cells[type].<span>innerText;
                    arr2[文本]</span>=<span>i;
                }
            }
        }
    </span>腳本>
頭>

<center>
<span>排序</span>表格</center>

    <tr>
        
                
                
                <p>
                    以上就是介紹了php使用js對表格進行排序,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。 </p>
                <p>
                    </p>
</tr></tbs.rows.length></tbs.rows.length></tbs.rows.length>
登入後複製
相關標籤:
lt
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板