在页面加载中插入可拖动的div无法正常工作

时间:2018-06-20 13:15:49

标签: jquery

我正在尝试动态插入可拖动的div。目前,我正在尝试在页面加载时插入。稍后我将其更改为按钮。页面加载时没有任何内容插入我的容器,我不明白为什么?

编辑:我已修正其他人指出的错字并将div插入页面,但div仍不可拖动,我不明白为什么?

//this makes elements with the draggable class draggable
 <script>
    $( function() {
      $( ".draggable" ).draggable();
    } );
//this inserts a draggable div on page load, will conert this to a button 
//call function later once i get inserting draggable divs working
    $(document).ready(function(){
        $('#Container').append($("<div class='draggable'> This should be draggable</div>"));
    });
    </script>
</head>
<body>
<!-- Putting divs inside this Container --->
    <div id="Container" style="border:solid; width:500px; height:500px;">
    </div>

1 个答案:

答案 0 :(得分:1)

在每个附加操作之后启动插件

$(document).ready(function(){
        $('#Container').append("<div class='draggable'> This should be draggable</div>");
        $(".draggable").draggable();
    });
相关问题