Jquery 可拖动/实时

发布于 2024-10-04 00:52:49 字数 441 浏览 0 评论 0原文

我有:

$(document).ready(function () {

      $(".div1, .div2, .div3, .div4, .div5").draggable();


      $("#menu").click(function () {

           $("<div class='div1'></div>").appendTo("#layout");

      });

});

但是可拖动功能仅适用于加载页面时已经存在的 div。当我动态添加时,我无法拖动它们。

我的HTML:

     <div id="layout">
       <div class="div1"></div>
     </div>

I have:

$(document).ready(function () {

      $(".div1, .div2, .div3, .div4, .div5").draggable();


      $("#menu").click(function () {

           $("<div class='div1'></div>").appendTo("#layout");

      });

});

But the draggable function works just to the divs that already exist when the page is loaded. When I add dynamically, I could not drag them.

My Html:

     <div id="layout">
       <div class="div1"></div>
     </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木森分化 2024-10-11 00:52:49

您只需使用 : 将可拖动处理程序添加到新的 div 中

 $("<div class='div1'></div>").appendTo("#layout").draggable();

这是一个实例

You just need to add the draggable handler to your new div with :

 $("<div class='div1'></div>").appendTo("#layout").draggable();

for example.

Here's a live example.

你与昨日 2024-10-11 00:52:49

在您的情况下,最简单的解决方案是在创建新元素时调用 .draggable() ,如下所示:

$("<div class='div1'></div>").appendTo("#layout").draggable();

In your case the easiest solution is to call .draggable() on the new elements as you create them, like this:

$("<div class='div1'></div>").appendTo("#layout").draggable();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文