为什么使用 $.post 功能创建的元素无法被 jquery UI 可放置功能识别?
当我直接创建以下行时,我可以将内容放在上面:
echo '<tr class="droptarget"><td>test</td></tr>';
但是当同一行放在 PHP 文件中并作为 $.post 调用的结果接收时,我无法通过 jQuery 访问 droptarget。
$.post('test.php', function(data) {
$('#ausgabe').html(data);
calculate();
});
这是根据jquery代码:
$('.element').draggable({
appendTo: 'body',
revert: 'invalid',
helper: 'clone'
});
$('.droptarget').droppable({
accept: '.element',
drop: function(event,ui) {
alert('hallo');
}
});
对于由 $.post 调用创建的可点击元素,我知道我必须使用以下元素: $('.element').on('click','.remove',function(e)...
但是,对于可丢弃的功能,这是如何完成的呢?
一
秒钟后就找到了这个解决方案:
$.post('test.php', { fn: '' }, function(data) {
$('#ausgabe').html(data);
$('.droptarget').droppable({
accept: '.zutat',
activeClass: 'drop-active',
hoverClass: 'drop-hover',
drop: function(event,ui) {
alert('hallo');
}
});
});
也许这对其他人有帮助...