dsyak22488 2015-08-03 15:35
浏览 76

使用脚本动态创建droppable div也是动态创建的

I am dynamically creating a list of droppable divs with the javascript also dynamically included. The php looks like this:

echo "<li class=\"grayborder txdkgray\"><div id=\"queue".$i."\" style=\"width:300px; height:30px; text-align:center;\">*Drag a file here to run* </div></li>";
echo "<script> $('#queue".$i."').droppable( {hoverClass: 'hovered', drop: handleQueueDrop} ); </script>";

The problem is that the divs it creates are not working, I can't drop anything into them and the function doesn't run when I do. Is this a problem which the way I am echoing them?

  • 写回答

1条回答 默认 最新

  • dpzbh1779 2015-08-03 15:42
    关注

    You need an space here

    ... id=\"queue".$i."\"style=\"width:300 ...
    

    like this

    ... id=\"queue".$i."\" style=\"width:300 ...
    

    Also, you should run your code after load event. Convert this

    echo "<script> $('#queue".$i."').droppable( {hoverClass: 'hovered', drop: handleQueueDrop} ); </script>";
    

    to this

    echo "<script> $(function(){ $('#queue".$i."').droppable( {hoverClass: 'hovered', drop: handleQueueDrop} ); }) </script>";
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料