droppable无法使用$ .post创建的元素

时间:2013-11-15 19:50:22

标签: javascript php jquery

为什么使用$ .post功能创建的元素无法通过jquery ui droppable功能识别?

当我直接创建以下行时,我可以删除它:

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)...

但是如何为droppable功能做到这一点?

1 个答案:

答案 0 :(得分:0)

一秒钟后发现了这个解决方案:

$.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');
    }
  });
});

也许这有助于其他人......

相关问题