感謝您提供任何幫助!目前,我使用一個用戶可分類的代碼來允許用戶按順序上下移動項目。現在,我想給每個這些項目提供一組「向上」和「向下」按鈕,讓用戶只需點擊一下即可上下移動項目。我試着返工論文的職位,但我似乎失去了一些東西明顯...用jquery向上和向下移動元素
jQuery Sortable Move UP/DOWN Button move up/down in 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')
});
缺少分號的錯別字正確的證明? – lifetimes 2013-03-18 20:05:25