<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>排序</title>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<style type="text/css">
img{
cursor: pointer;
width:20%;
margin:10px
}
</style>
</head>
<body>
<div class="sortable">
<img id="1" src="1.jpg" alt="" />
<img id="2" src="1.jpg" alt="" />
<img id="3" src="1.jpg" alt="" />
<img id="4" src="1.jpg" alt="" />
</div>
<script>
$(function() {
$(".sortable").sortable({
update: function(event, ui) { //更新排序之后
var categoryids = $(this).sortable("toArray");
var $this = $(this);
console.log(categoryids);
$.ajax({
url: '后台url',
type: 'POST',
data: 'categoryids=' + categoryids,
success: function(json) {
if(json == 1) {
layer.msg('移动成功', {
icon: 1
});
} else {
$this.sortable("cancel");
layer.msg('移动失败', {
icon: 2
});
}
}
});
}
});
$(".sortable").disableSelection();
});
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>排序</title>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<style type="text/css">
img{
cursor: pointer;
width:20%;
margin:10px
}
</style>
</head>
<body>
<div class="sortable">
<img id="1" src="1.jpg" alt="" />
<img id="2" src="1.jpg" alt="" />
<img id="3" src="1.jpg" alt="" />
<img id="4" src="1.jpg" alt="" />
</div>
<script>
$(function() {
$(".sortable").sortable({
update: function(event, ui) { //更新排序之后
var categoryids = $(this).sortable("toArray");
var $this = $(this);
console.log(categoryids);
$.ajax({
url: '后台url',
type: 'POST',
data: 'categoryids=' + categoryids,
success: function(json) {
if(json == 1) {
layer.msg('移动成功', {
icon: 1
});
} else {
$this.sortable("cancel");
layer.msg('移动失败', {
icon: 2
});
}
}
});
}
});
$(".sortable").disableSelection();
});
</script>
</body>
</html>