【问题标题】:how to make a div movable up and down and also swap id variables using jquery如何使 div 上下移动并使用 jquery 交换 id 变量
【发布时间】:2014-01-15 14:28:37
【问题描述】:

是否可以让 div 上下移动并在上下切换时更改 ID 的值?

<div id="main_window">
     <div id="window_1"> //this window moves down and also 
         <input id="var_1"> //gets the value of "3" from the div below
     </div>
     <div id="window_3"> //this window moves up and also
         <select id="var_3"></select> //gets the value of "1" from the div above
     </div>
     <div id="window_6">
         <textarea id="var_6"></textarea>
     </div>
     <div id="window_8">
         <input id="var_7">

     </div>
</div>

向上推的 div 应该获取最高的 id/name 值,但不能只切换 id 变量的内容。

只要完成目标,就可以通过点击或拖动来完成移动事件

【问题讨论】:

  • 您是通过拖放或点击任何事件来移动 div?
  • 放下或点击,只要目标可以完成
  • 您没有编写任何 javascript...您应该自己尝试解决问题...是的,有可能...
  • 这就是为什么我问这是否可能,因为我还没有这样做。

标签: javascript jquery html toggle moveabletype


【解决方案1】:

对于使用 jQuery 的简单可移动 div,我建议使用 jQueryUI Sortable

您可以在 update [docs] 等事件处理程序中重新分配 id/name 值

【讨论】:

  • 是的,不过您需要致电refresh [docs]
  • 试过了,它确实支持动态元素,但现在的问题是更新 id / name 变量
  • 就像我说的,你应该使用像 update 这样的事件记录
  • 已经有了答案 $('#selectable .count').prop('value', function(i) { return ++i; });
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-10
  • 2012-06-13
相关资源
最近更新 更多