时间:2021-07-01 10:21:17 帮助过:37人阅读
页面js:
1 $(function() { 2 $(".m_title").bind(‘mouseover‘, 3 function() { 4 $(this).css("cursor", "move") 5 }); 6 7 var $show = $("#loader"); //进度条 8 var $orderlist = $("#orderlist"); 9 var $list = $("#module_list"); 10 11 $list.sortable({ 12 opacity: 0.6, 13 revert: true, 14 cursor: ‘move‘, 15 handle: ‘.m_title‘, 16 update: function() { 17 var new_order = []; 18 $list.children(".modules").each(function() { 19 new_order.push(this.title); 20 }); 21 var newid = new_order.join(‘,‘); 22 var oldid = $orderlist.val(); 23 $.ajax({ 24 type: "post", 25 url: "update.php", 26 data: { 27 id: newid, 28 order: oldid 29 }, 30 //id:新的排列对应的ID,order:原排列顺序 31 beforeSend: function() { 32 $show.html("<img src=‘images/load.gif‘ /> 正在更新"); 33 }, 34 success: function(msg) { 35 $show.html(""); 36 } 37 }); 38 } 39 }); 40 });
拖动后保存到数据库,ajax.php中的代码:
1 $order = $_POST[‘order‘]; 2 $itemid = trim($_POST[‘id‘]); 3 if (!empty($itemid)) { 4 if ($order != $itemid) { 5 $query = mysql_query("update sortlist set sort=‘$itemid‘ where id=1"); 6 if ($query) { 7 echo $itemid; 8 } else { 9 echo "none"; 10 } 11 } 12 }
本文转自:https://www.sucaihuo.com/php/69.html 转载请注明出处!
PHP+jQuery-ui拖动浮动层排序并保存到数据库实例
标签:拖动 put alt hid url 技术 ges target mysq