如何自动将拖放效果应用于动态添加的元素? [英] How to auto apply drag and drop effect to dynamically added element?
本文介绍了如何自动将拖放效果应用于动态添加的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jquery ui在一系列DIV上施加拖放效果,例如:
I use jquery ui to apply a drag and drop effect on a serial of DIVs, for example:
<div class="draggable">...</div>
<div class="draggable">...</div>
<div class="draggable">...</div>
<div class="draggable"> this DIV was dynamically added, not draggable </div>
问题是动态添加的DIV不会应用此效果,我也该如何在新成员上应用此效果?
The problem is dynamically added DIVs won't have this effect applied, how can i apply this effect on new members too?
推荐答案
您不能将.live()函数直接与.draggable()一起使用,但可以将.live()与mouseover事件一起使用并重新连接.像这样将鼠标悬停在draggable()上.
You cannot use the .live() function with .draggable() directly, but you can use .live() with the mouseover event and re-attach .draggable() on mouseover like this.
$('.draggable').live('mouseover',function(){
$(this).draggable();
});
这篇关于如何自动将拖放效果应用于动态添加的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文