weixin_33727510 2015-12-15 21:05 采纳率: 0%
浏览 27

HTML5拖放式Ajax

I m trying to handle dragstart event on Ajax Dom Elements Loaded but doesn't work. Here is how I handle the Dragstart Event to get the ID of the Element being Moved:

  $(document).on(".dragItem", "dragstart", function (ev) {

        ev.originalEvent.dataTransfer.setData("text", ev.target.id);
    });

For any element loaded on the Page the Dragstart is handled by the code above.

However, when I create an Html div using JS later in the Code, the Event doesn't respond.

<div class="dragItem" draggable='true'>My Drag Item </div>

In fact I'm receiving JSON Data through jquery Ajax, then update The DOM with the HTML Created.

  • 写回答

1条回答 默认 最新

  • YaoRaoLov 2015-12-15 21:49
    关注

    I was able to fix my issue. Once DOM is updated with JSON Data formatted to HTML, I create a jquery Object pointing to newly inserted elements, then I reapply the dragstart event handling.

    $("#cellphonestock").html(total);
    var d = $("#cellphonestock .dragItem");
    
                d.on( "dragstart", function (ev) {
                    ev.originalEvent.dataTransfer.setData("text", ev.target.id);
                });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样