在Div中拖动元素。不要拖延

时间:2012-04-23 12:49:22

标签: jquery jquery-ui

我有以下div:

<div id="Cc" style="height: 40px; width: 100%; border: 1px solid black" class="ui-sortable ui-droppable">
                </div>

我已成功连接2个可拖动的ul,在此div中创建一个新的水平列表,当我点击列表中的元素时,它会被删除:

 $("#Cc").droppable({
            drop: function (event, ui) {
                var a = $(ui.draggable).attr('id');
                ts = "";
                if (dlistCc.length > 0)
                    ts = ",";
                var checkExists = document.getElementById("Id_" + a);
                if (checkExists) {
                    alert("Already there !");
                } else {
                    dlistCc.push(a);
                    var listElem = "<li  id=\"Id_" + a + "\"onclick=\"RemFromList('" + a + "_" + name + "_" + "#Cc" + "');\" style=\"font-weight:bold;margin-top: 1px;list-style-type: none;display:inline; margin-bottom: 3px; cursor:pointer; font-size: 11px; color:Black; padding-top: 1px; padding-bottom: 1px;  margin-left:2px; width:150px;\"><a>" + ts + $.trim($(ui.draggable).text()).replace(/\s(?=\s)/g, '') + "</a></li>";
                    $("#Cc").append(listElem);

                }
                NamesCc = NamesCc + listElem;
            }

        });

,但我有以下问题:我可以在我自己的div中拖动元素,并复制元素。我怎么能阻止它?

enter image description here
提前致谢 !

1 个答案:

答案 0 :(得分:0)

var a = $(ui.draggable).attr('id');

var checkExists = document.getElementById("Id_" + a);

这两行之间有区别,你能看到吗?

<子> "Id_" +