当您使用jQuery UI将其拖动到另一个上时交换元素 [英] Swap elements when you drag one onto another using jQuery UI

查看:266
本文介绍了当您使用jQuery UI将其拖动到另一个上时交换元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上安排了一些元素:

I have an arrangement of elements on a page:

<div>
  <div class="dragdrop" style="top:0px;  left: 0px;  ">1</div>
  <div class="dragdrop" style="top:40px; left: 0px;  ">2</div>
  <div class="dragdrop" style="top:60px; left: 0px;  ">3</div>
  <div class="dragdrop" style="top:0px;  left: 100px;">4</div>
  <div class="dragdrop" style="top:40px; left: 100px;">5</div>
  <div class="dragdrop" style="top:60px; left: 100px;">6</div>
</div>

我如何使用jQuery UI(Draggable / Droppable)来使它成为一个div被放弃到另一个,他们互换位置? (如果它被拖到别的地方,它会恢复到原来的位置。)

How can I use jQuery UI (Draggable / Droppable) to make it so that if one div is dropped onto another, they swap positions? (And if it's dragged anywhere else, it reverts back to its old position.)

谢谢。

推荐答案

下面是一个示例,您可以如何通过拖放来交换元素 http: //jsfiddle.net/76yRN/1/

Here is an example of how you can swap elements with drag and drop http://jsfiddle.net/76yRN/1/

另一个关于在jquery中交换元素的问题 jQuery可拖动项在被交换后失去了可拖动性(用jsfiddle示例)

Another question about swapping elements in jquery jQuery draggable items lose their draggability after being swapped (with jsfiddle example)

希望这有助于

这篇关于当您使用jQuery UI将其拖动到另一个上时交换元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆