方法一
var swapItems = function(arr, index1, index2){
arr[index1] = arr.splice(index2,1,arr[index1])[0]
return arr
}
var arr = [1,2,3]
var newArr = []
upData (arr, index) {
if (this.arr.length > 1 && index !== 0) {
newArr = swapItems(arr, index, index - 1)
}
}
downData (arr, index) {
if (this.arr.length > 1 && index !== (this.arr.length - 1)) {
newArr = swapItems(this.arr, index, index + 1)
}
}
方法二
.item:first-of-type .up { color:#ccc; cursor:not-allowed; }
.item:last-of-type .down { color:#ccc; cursor:not-allowed; }
upBtn.click(function () {
$(this).parent().parent().prev().before($(this).parent().parent());
return false;
});
downBtn.click(function () {
$(this).parent().parent().next().after($(this).parent().parent());
return false;
});