簡體   English   中英

如何在單擊時使元素移動到另一個元素,然后返回到JQuery中的上一個位置?

[英]How to to make element move to another element then when click, return to previous position in JQuery?

目的

  • 使用什么方法使項目3移至另一個容器。
  • 然后,如果再次單擊,則將項目返回到先前位置
  • 此功能應適用於所有項目。

jQuery的

 $('#item3').click(function(){
       // What method to use to make item_1 move to another container.
       // Then if click again return the item to previous position
 });

在此處輸入圖片說明

檢查演示

的HTML

<div id="start">
<div class="element">one</div>
<div class="element">two</div>
<div class="element">three</div>
</div>

<div id="target"></div>

jQuery的

$('.element').click(function() {
var cont = $(this).parent().attr('id');
if (cont == 'start') {
    var place = '#target';
} else {
    var place = '#start';
}
$(place).append($(this));
});

您可以使用jQuery UI的拖放插件。

如果您想繼續使用此代碼,則可以通過onClick函數嘗試使用此代碼。

.JS

function onclickIteam(iteamId){
    var x = if('#iteamId').html();
    if(if('#iteamId').parent().prop("id") == "my_inventory"){
        //$('#iteamId').detach();
        $('#server_inventory').append(x);
    }else{
        //$('#iteamId').detach();
        $('#my_inventory').append(x);
    }
`}`

暫無
暫無

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

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