JQuery實(shí)現(xiàn)表格數(shù)據(jù)行上移與下移
本文實(shí)例為大家分享了JQuery實(shí)現(xiàn)表格數(shù)據(jù)行上移與下移的具體代碼,供大家參考,具體內(nèi)容如下
效果展示

代碼實(shí)現(xiàn)
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="utf-8">
? ? <title>Bootstrap 實(shí)例 - 條紋表格</title>
? ? <link rel="stylesheet" >
? ? <script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
? ? <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
?
? ? <style type="text/css">
? ? ? ? .moveUpOrDown {
? ? ? ? ? ? background-color: #5BC0DE;
? ? ? ? ? ? border-radius: 3px;
? ? ? ? ? ? cursor: pointer;
? ? ? ? ? ? color: #FFFFFF;
? ? ? ? ? ? padding: 2px;
? ? ? ? ? ? font-size: 12px;
? ? ? ? }
? ? </style>
?
? ? <script type="text/javascript">
? ? ? ? $(function () {
? ? ? ? ? ? /**
? ? ? ? ? ? ?* 為 上移 、下移 按鈕綁定點(diǎn)擊事件
? ? ? ? ? ? ?*/
? ? ? ? ? ? $("body").on("click", ".moveUpOrDown", function () {
? ? ? ? ? ? ? ? var text = $(this).text();
? ? ? ? ? ? ? ? if (text == "上移") {
? ? ? ? ? ? ? ? ? ? var prevTr = $(this).parent().parent().prevAll();
? ? ? ? ? ? ? ? ? ? /**如果當(dāng)前行不是第一行,則上移它*/
? ? ? ? ? ? ? ? ? ? if (prevTr.length > 0) {
? ? ? ? ? ? ? ? ? ? ? ? var preTemp = prevTr.first();
? ? ? ? ? ? ? ? ? ? ? ? var thisHr = $(this).parent().parent();
? ? ? ? ? ? ? ? ? ? ? ? /**將上一行與本行交互內(nèi)容,replaceWith 方法內(nèi)容為 html 內(nèi)容
? ? ? ? ? ? ? ? ? ? ? ? ?* 可參考文檔:http://www.w3school.com.cn/jquery/manipulation_replacewith.asp*/
? ? ? ? ? ? ? ? ? ? ? ? thisHr.replaceWith("<tr>" + preTemp.html() + "</tr>");
? ? ? ? ? ? ? ? ? ? ? ? preTemp.replaceWith("<tr>" + thisHr.html() + "</tr>");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? } else if (text == "下移") {
? ? ? ? ? ? ? ? ? ? var nextTr = $(this).parent().parent().next();
? ? ? ? ? ? ? ? ? ? if (nextTr.length > 0) {
? ? ? ? ? ? ? ? ? ? ? ? var thisHr = $(this).parent().parent();
? ? ? ? ? ? ? ? ? ? ? ? /**將本行與下一行交互內(nèi)容,replaceWith 方法內(nèi)容為 html 內(nèi)容 */
? ? ? ? ? ? ? ? ? ? ? ? thisHr.replaceWith("<tr>" + nextTr.html() + "</tr>");
? ? ? ? ? ? ? ? ? ? ? ? nextTr.replaceWith("<tr>" + thisHr.html() + "</tr>");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? });
? ? ? ? });
? ? </script>
?
</head>
<body>
?
<table class="table table-striped">
? ? <caption>條紋表格布局</caption>
? ? <thead>
? ? <tr>
? ? ? ? <th>名稱</th>
? ? ? ? <th>城市</th>
? ? ? ? <th>郵編</th>
? ? ? ? <th>排序</th>
? ? </tr>
? ? </thead>
? ? <tbody>
? ? <tr>
? ? ? ? <td>Tanmay1</td>
? ? ? ? <td>Bangalore</td>
? ? ? ? <td>560001</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Sachin1</td>
? ? ? ? <td>Mumbai</td>
? ? ? ? <td>400003</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Uma1</td>
? ? ? ? <td>Pune</td>
? ? ? ? <td>411027</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Tanmay2</td>
? ? ? ? <td>Bangalore</td>
? ? ? ? <td>560001</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Sachin2</td>
? ? ? ? <td>Mumbai</td>
? ? ? ? <td>400003</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Uma2</td>
? ? ? ? <td>Pune</td>
? ? ? ? <td>411027</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Tanmay3</td>
? ? ? ? <td>Bangalore</td>
? ? ? ? <td>560001</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Sachin3</td>
? ? ? ? <td>Mumbai</td>
? ? ? ? <td>400003</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? <tr>
? ? ? ? <td>Uma3</td>
? ? ? ? <td>Pune</td>
? ? ? ? <td>411027</td>
? ? ? ? <td><span class="moveUpOrDown">上移</span> | <span class="moveUpOrDown">下移</span></td>
? ? </tr>
? ? </tbody>
</table>
?
</body>
</html>以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery表格行上移下移和置頂?shù)膶?shí)現(xiàn)方法
- jQuery實(shí)現(xiàn)表格行上移下移和置頂?shù)姆椒?/a>
- JQuery實(shí)現(xiàn)Table的tr上移下移功能
- JS與jQuery實(shí)現(xiàn)ListBox上移,下移,左移,右移操作功能示例
- JQuery實(shí)現(xiàn)table中tr上移下移的示例(超簡單)
- jQuery Easyui datagrid行內(nèi)實(shí)現(xiàn)【添加】、【編輯】、【上移】、【下移】
- jQuery基于排序功能實(shí)現(xiàn)上移、下移的方法
- jQuery Easyui Datagrid實(shí)現(xiàn)單行的上移下移及保存移動(dòng)的結(jié)果
- jquery實(shí)現(xiàn)標(biāo)簽上移、下移、置頂
相關(guān)文章
jquery仿百度經(jīng)驗(yàn)滑動(dòng)切換瀏覽效果
本文給大家分享的是使用jQuery實(shí)現(xiàn)仿百度經(jīng)驗(yàn)華東切換瀏覽效果,非常的炫酷,推薦給大家。有需要的小伙伴可以參考下2015-04-04
基于jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)添加刪除代碼分享
這篇文章主要介紹了基于jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)添加刪除功能,推薦給大家,有需要的小伙伴可以參考下。2015-08-08
jQuery實(shí)現(xiàn)的簡單拖拽功能示例【測試可用】
這篇文章主要介紹了jQuery實(shí)現(xiàn)的簡單拖拽功能,涉及jQuery基于事件響應(yīng)及頁面元素屬性動(dòng)態(tài)操作實(shí)現(xiàn)拖拽功能的相關(guān)操作技巧,需要的朋友可以參考下2018-08-08
jQuery+css+html實(shí)現(xiàn)頁面遮罩彈出框
面遮罩彈出框已經(jīng)不是一個(gè)陌生的話題了,實(shí)現(xiàn)的方法大同小異多種多樣,今天用jQuery實(shí)現(xiàn)頁面遮罩彈出框,主要用的技術(shù)有JQuery,css和html,感興趣的朋友可以參考下哈2013-03-03
如何解決jQuery EasyUI 已打開Tab重新加載問題
最近在項(xiàng)目中遇到這樣的需求,要求實(shí)現(xiàn)點(diǎn)擊左側(cè)已經(jīng)打開的tab可以刷新重新加載datagrid。下面給大家分享實(shí)現(xiàn)代碼,一起看看吧2016-12-12
jQuery實(shí)現(xiàn)飛機(jī)大戰(zhàn)小游戲
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)飛機(jī)大戰(zhàn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07
JQuery團(tuán)隊(duì)打造的javascript單元測試工具QUnit介紹
元測試又稱為模塊測試,是針對程序模塊(軟件設(shè)計(jì)的最小單位)來進(jìn)行正確性檢驗(yàn)的測試工作。單元測試主要是用來檢驗(yàn)程式的內(nèi)部邏輯,也稱為個(gè)體測試、結(jié)構(gòu)測試或邏輯驅(qū)動(dòng)測試。通常由撰寫程式碼的程式設(shè)計(jì)師負(fù)責(zé)進(jìn)行。2010-02-02
jQuery+css3實(shí)現(xiàn)Ajax點(diǎn)擊后動(dòng)態(tài)刪除功能的方法
這篇文章主要介紹了jQuery+css3實(shí)現(xiàn)Ajax點(diǎn)擊后動(dòng)態(tài)刪除功能的方法,可實(shí)現(xiàn)點(diǎn)擊選區(qū)后出現(xiàn)選區(qū)收縮、滾動(dòng)消失的效果,涉及jquery結(jié)合Ajax與數(shù)學(xué)運(yùn)算實(shí)時(shí)操作頁面元素的相關(guān)技巧,需要的朋友可以參考下2015-08-08

