感谢您的任何帮助,您可以提供!目前,我使用 ui-sortable 代码来允许用户按顺序上下移动项目。现在,我想为这些项目中的每一个提供一组“向上”和“向下”按钮,允许用户通过单击来上下移动项目。我试过修改这些帖子,但我似乎遗漏了一些明显的东西......
jQuery Sortable Move UP/DOWN 按钮 在jquery中向上/向下移动
我想不知何故我没有将 jquery 应用于正确的元素。我的 jsfiddle 在这里:http: //jsfiddle.net/kevindp78/vexw5/2/代码如下。
HTML
<div id="box" class="ui-sortable" style="display: block;">
<div class="leg">
<a class="image">IMG1</a>
<div class="details">
<h3><a href="/details">Info</a></h3>
<span class="moreinfo">MoreInfo</span>
</div>
<div class="clear"></div>
<div class="up-down">
<p>Change Order</p>
<div class="up">
<input type="button" value="Up" class="up-button"/>
</div>
<div class="down">
<input type="button" value="down" class="down-button"/>
</div>
</div>
<div class="morestuff">
Stuff1
</div>
</div>
<div class="leg">
<a class="image">IMG2</a>
<div class="details">
<h3><a href="/details">Info</a></h3>
<span class="moreinfo">MoreInfo</span>
</div>
<div class="clear"></div>
<div class="up-down">
<p>Change Order</p>
<div class="up">
<input type="button" value="Up" class="up-button"/>
</div>
<div class="down">
<input type="button" value="down" class="down-button"/>
</div>
</div>
<div class="morestuff">
Stuff2
</div>
</div>
<div class="leg">
<a class="image">IMG3</a>
<div class="details">
<h3><a href="/details">Info</a></h3>
<span class="moreinfo">MoreInfo</span>
</div>
<div class="clear"></div>
<div class="up-down">
<p>Change Order</p>
<div class="up">
<input type="button" value="Up" class="up-button"/>
</div>
<div class="down">
<input type="button" value="down" class="down-button"/>
</div>
</div>
<div class="morestuff">
Stuff3
</div>
</div>
JS
$('up-button').click(function(){
$(this).parent('.leg').insertBefore.previous('.leg')
});
$('.down-button').click(function(){
$(this).parent('.leg').insertAfter.next('.leg')
});