簡體   English   中英

jQuery UI Droppable接受條件不起作用

[英]JQuery UI droppable accept condition not working

搜索谷歌和stackoverflow近兩個小時后,我只是無法深入了解這一點。 我在我的代碼中找不到問題:

HTML:

<ul style="list-style:none;cursor:default;">
    <li>uuu</li>
    <li>aaa</li>
</ul>

<div id="canvas" style="height:300px;width:400px;border: 1px solid black"></div>

使用Javascript:

$("li").draggable({
    helper: function () {
       return $("<div class='helper'>test</div>");
    }
});


$("#canvas").droppable({
    accept: ".helper",
    drop: function (ev, ui) {
        var h = ui.helper.clone(false) //$(ui.helper).clone(false) shows the same behaviour
               .removeClass('ui-draggable-dragging')
               .css({position:'relative', left:0, top:0});
        $(this).append(h);
    }
});


$("body").disableSelection();

無論我做什么,只要我指定.droppable的“ accept”選項,$(“#canvas”)都將不再接收任何元素。 這是小提琴: http : //jsfiddle.net/98tdy/誰能告訴我這個問題嗎?

您的代碼無效,因為您指定了<div id="#canvas"

因此$("#canvas")無法使用。 只需將id更改為canvas

檢查這個小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM