日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

jquery實現表格行的上下移動和置頂_jquery

作者:每天進步一點_點 ? 更新時間: 2022-04-25 編程語言

本文實例為大家分享了jquery實現表格行的上下移動和置頂的具體代碼,供大家參考,具體內容如下

先上效果圖:

點擊上移、下移、置頂,可以實現對應的效果。

上代碼:


? ? 刪除
? ? {{# if(index > 0){ }} ?//layui的模板語法
? ? 上移
? ? 置頂
? ? 下移
? ? {{# } else if(index ==0){ }}
? ? 下移
? ? 上移
? ? 置頂
? ? {{# } }}
$('#content').children("tr").each(function (index) {
? ? var $that_tr=$(this);
? ? var diseaseDoctorId=$that_tr.data("id");
? ? ? $that_tr.children("td:last-child").children("a").each(function () {
? ? ? ? ? var $that_a=$(this);
? ? ? ? ? var action=$that_a.data("opt");
? ? ? ? ? ?$that_a.on('click',function (e) {
? ? ? ? ? ? ?switch (action){
? ? ? ? ? ? ? ?case 'delete':
? ? ? ? ? ? ? ?var name = $that.parent('td').siblings('td[data-field=name]').text();
? ? ? ? ? ? ? ? //詢問框
? ? ? ? ? ? ??layerTips.confirm('確定要刪除[ ' + name + ' ] ?', { icon: 3, title: '系統提示' }, function (index) {


? ? ? ? ? ? ? ? ? ? $.ajax({
? ? ? ? ? ? ? ? ? ? ? ? ?url:'<%=staticPath%>/doctor/diseaseDoctor/delere/'+diseaseDoctorId,
? ? ? ? ? ? ? ? ? ? ? ? ?type:'get',
? ? ? ? ? ? ? ? ? ? ? ? ? dataType:'json',
? ? ? ? ? ? ? ? ? ? ? ? ? success:function (result) {
? ? ? ? ? ? ? ? ? ? ? ? ? ?if (result.code==200) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?layer.msg("刪除成功");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?location.reload();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?layer.msg("刪除失敗");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ? ? ? ? ? ? ?error:function (result) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?layer.msg("刪除失敗");
? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?});
? ? ? ? ? ? ? ? ? ? ? ? ? ?});
? ? ? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ? ? ?case 'moveup':
? ? ? ? ? ? ? ? ? ? ? ? ? ?console.log("上移");
? ? ? ? ? ? ? ? ? ? ? ? ? ?var prev=$that_a.parents("tr").prev();
? ? ? ? ? ? ? ? ? ? ? ? ? ?var prevIndex=$(prev).index('tr');
? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.parents("tr").insertBefore(prev);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(prevIndex==1){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.siblings("a[data-opt=movetop]").prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.siblings("a[data-opt=movedown]").prop('style','display:');
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$(prev).children("td:last-child").find("a[data-opt=movedown]").prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $(prev).children("td:last-child").find("a[data-opt=moveup]").prop("style","display:");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $(prev).children("td:last-child").find("a[data-opt=movetop]").prop("style","display:");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ? ? ?case 'movetop':
? ? ? ? ? ? ? ? ? ? ? ? ? ?console.log("置頂");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?var first=$that_a.parents("tr").siblings("tr:first");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.parents("tr").insertBefore(first);
? ? ? ? ? ? ? ? ? ? ? ? ? ?$(first).children("td:last-child").find("a[data-opt=movedown]").prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ?$(first).children("td:last-child").find("a[data-opt=moveup]").prop("style","display:");
? ? ? ? ? ? ? ? ? ? ? ? ? ?$(first).children("td:last-child").find("a[data-opt=movetop]").prop("style","display:");
? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.siblings("a[data-opt=moveup]").prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.siblings('a[data-opt=movedown]').prop("style","display:");
? ? ? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ? ? ?case 'movedown':
? ? ? ? ? ? ? ? ? ? ? ? ? ?console.log("下移");
? ? ? ? ? ? ? ? ? ? ? ? ? ?var next=$that_a.parents("tr").next();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.parents("tr").insertAfter(next);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.siblings("a[data-opt=moveup]").prop("style","display:");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.siblings("a[data-opt=movetop]").prop("style","display:");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$that_a.prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$(next).children("td:last-child").find("a[data-opt=moveup]").prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$(next).children("td:last-child").find("a[data-opt=movetop]").prop("style","display:none");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?$(next).children("td:last-child").find('a[data-opt=movedown]').prop("style","display:");


? ? ? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? });
? ? });
});

我是做后臺的,js寫的可能比較 low,各位看看即可,歡迎提出修改意見。

原文鏈接:https://blog.csdn.net/zhangxiaoyang0/article/details/77677217

欄目分類
最近更新