jQuery Sortable上移/下移按钮 [英] jQuery Sortable Move UP/DOWN Button
问题描述
我目前有一个运行良好的jQuery可排序列表.我能够移动"li"元素.但是,如何制作一个按钮来将特定的"li"元素向上移动一个,而将上方的一个向下移动(当然,对于向下按钮则相反)?我环顾谷歌,发现很少.甚至一个链接也很棒!
I currently have a jQuery sortable list working perfectly. I am able to move the 'li' elements around. However, how can I make a button to move a specific 'li' element up by one and the one above to move down (and of course the opposite for a down button)? I have looked around google and found very little. Even a link would be fantastic!
谢谢!
推荐答案
如果您具有以下html代码:
If you have following html code:
<button id="myButtonUp">myButtonTextForUp</button>
<button id="myButtonDown">myButtonTextForDown</button>
<ul>
<li>line_1</li>
<li>line_2</li>
<li>line_3</li>
</ul>
我假设您已经准备好标记每个li
的东西,因此接下来,我假设标记的li
具有类markedLi
;从理论上讲,以下代码应使该元素向上或向下移动(完全未经测试,这是当然的):
I assume you have allready something to mark each li
s, so following I assume the marked li
has the class markedLi
; Following code should in theory move that element up or down (totally untested off course):
$('#myButtonUp').click(function(){
var current = $('.markedLi');
current.prev().before(current);
});
$('#myButtonDown').click(function(){
var current = $('.markedLi');
current.next().after(current);
});
这篇关于jQuery Sortable上移/下移按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!