如何移动附加的 div?

How can i move an appended div?

我有这个代码:

<div id="plan">
    <div id="" class="move circle pe">1</div>
</div>

$('.move').draggable({
      containment: '#plan',
      stop: function(e, ui) {
        var offset = $(this).offset(),
          x = offset.left,
          y = offset.top;
        //callback will be here
        alert("posição x: " + x + " posição y:" + y);
      }
    });

我可以移动数字 1 的 div,但是当我生成一个新的 div

function createStation(station){
        number = window.prompt("Escolha o numero para o posto");
        id = station+number;
        $("#plan").append("<div id='"+id+"' class='move circle pe'>"+number+"</div>");
    }

div 出现了,但我无法移动它。 我需要让它移动,但也要提醒它的位置(未来回调)

请检查 jsfiddle:

https://jsfiddle.net/mornaistar/q180z7Ls/11/

我会在您的每个新项目上创建一个额外的绑定功能 draggable() 例如,将 class move 重新绑定到 draggable()

添加了一个函数dragger()

function dragger() {
    $('.move').draggable({
        containment: '#plan',
        stop: function(e, ui) {
            var offset = $(this).offset(),
                x = offset.left,
                y = offset.top;
            //callback para salvar em php
            alert("posição x: " + x + " posição y:" + y);
        }
    });
}

Fiddle 示例:https://jsfiddle.net/2f4c36v7/