代码之家  ›  专栏  ›  技术社区  ›  Some_Dude

在页面加载中插入可拖动div不工作

  •  0
  • Some_Dude  · 技术社区  · 7 年前

    我试图动态地插入可拖动的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 回复  |  直到 7 年前
        1
  •  1
  •   madalinivascu    7 年前

    启动插件 之后 每个追加

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