jQuery UI draggable在新创建的DOM元素上不起作用 [英] jQuery UI draggable is not working on newly created DOM element
问题描述
$('div.draggable')draggable(); //现有元素,它工作:)
$('p.draggable')。draggable(); //新创建的段落与相同的类名称,它根本不工作:(
提前感谢! !!
我正在尝试这个:
<脚本类型=text / javascript>
$(document).ready(function(){
$('body')。append('< p class =draggable>新创建的段落< ; / p>');
$('p.draggable')。draggable(); ** //这不工作**
});
< / script>
然而不知怎的,这是工作
< script type =text / javascript>
$(document).ready(function(){
$('body')。append('< ; p class =draggable>新创建的段落< / p>')
.find('p.draggable')。draggable(); **这是工作**
});
< / script>
我知道它已经有一段时间了,但这个问题rec如同其他人所提到的那样,您必须在新创建的项目上重新运行 .draggable()
,但是如果您定义了某些选项,则不起作用 .draggable()
。还有什么不起作用的是把$(code)$()。draggable()放在一个函数中,然后在创建一个新元素后调用该函数
无论如何,长篇小说 - >放置 $()。draggable()
在一个功能中设置,然后在创建新的元素DID WORK后调用该函数,但是我禁止使用文档准备就绪
函数..... ,它的工作。
您可以多次调用该函数,并在每个创建的元素后继续工作。看来,如果它在 document.ready
声明中,那么它的1投票交易..
希望有所帮助。
I have some DOM element which is draggable using jQuery UI.All are working fine but when i create some element using jQuery , then they are not draggable at all. i.e
$('div.draggable').draggable(); //Existing element , it works :)
$('p.draggable').draggable() ; //Newly created paragraph with same class name, it doesnt work at all :(
Thanks in advance !!!
I am trying This :
<script type="text/javascript">
$(document).ready(function(){
$('body').append('<p class="draggable">Newly Created Paragraph</p>');
$('p.draggable').draggable(); **//This is not working**
});
</script>
However Somehow this is working
<script type="text/javascript">
$(document).ready(function(){
$('body').append('<p class="draggable">Newly Created Paragraph</p>')
.find('p.draggable').draggable(); **This is working**
});
</script>
I know its been a while, but this problem recently bugged me too. As someone else mentioned, you got to rerun .draggable()
on the newly created item, but that doesn't work if you defined certain options in your .draggable()
. Also what didn't work was putting the $().draggable()
in a function and then calling the function after creating a new element (this trick does however work with resetting droppables - go figure).
Anyway, long story short -> Putting the $().draggable()
setup in a function and then calling the function after creating new element DID WORK, but i had to TAKE IT OUT of the document ready
function..... after i disabled that, it worked.
You can call that function as many times and it keeps on working after every created element. It seems if it's in the document.ready
statement then its a 1 shot deal..
Hope that helps.
这篇关于jQuery UI draggable在新创建的DOM元素上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!