簡體   English   中英

使用單擊按鈕將jQuery UI可排序元素設置為第一個位置

[英]Use a button click to set a jQuery UI sortable element to first position

我試圖將以下函數添加到可排序的div組。 我想在每個div中都有一個按鈕(可能是任何東西),點擊它時會將它放在組的第一個位置。

<div id="sortable" class="content">
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 1</span></div>
        This is div 1.
        <br/><input type="button" name="button1" id="button1" value="Make me First"/>
    </div>
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 2</span></div>
        This is div 2.
        <br/><input type="button" name="button2" id="button2" value="Make me First"/>
    </div>
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 3</span></div>
        This is div 3.
        <br/><input type="button" name="button3" id="button3" value="Make me First"/>
    </div>
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 4</span></div>
        This is div 4.
        <br/><input type="button" name="button4" id="button4" value="Make me First"/>
    </div>
</div>

這些是div。

$(function() {  
    $( "#sortable" ).sortable({ 
        handle:".tile_header",
        revert:true
    });  
});  

這是我對可排序的呼吁。

我已經創建了一個顯示我的意思的jsFiddle 我試圖查看是否有可能,但沒有找到類似的東西。

有任何想法嗎?

 $(function () {      
    $("input:button").click(function () {
        $(this).parents(".tile").prependTo("#sortable");
    });
 });

http://jsfiddle.net/GrDBW/2/

我不認為這是您的代碼工作的正確標記。

我正在閱讀jquery sortable()API文檔,根據我的閱讀,你必須提供列表中的元素,即使你想將它顯示為網格。

http://jqueryui.com/sortable/#display-grid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM