Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery拖放在td中不起作用_Jquery - Fatal编程技术网

JQuery拖放在td中不起作用

JQuery拖放在td中不起作用,jquery,Jquery,这是我使用的脚本 $(function () { $("#header").draggable({ helper: "clone", cursor: 'move', tolerance: 'fit', containment: '#shoppingCart2' }); $("#shoppingCart2").droppable({ drop: function (e, ui) { if ($(ui.

这是我使用的脚本

$(function () {

     $("#header").draggable({
   helper: "clone",
    cursor: 'move',
    tolerance: 'fit',
     containment: '#shoppingCart2'
});

    $("#shoppingCart2").droppable({

        drop: function (e, ui) {

            if ($(ui.draggable)[0].id != "") {
                x = ui.helper.clone();
            ui.helper.remove();
            x.draggable({
                helper: 'original',
                containment: '#shoppingCart2 ',
                tolerance: 'fit'
            });

            x.appendTo('#container');
        }

        }
    });


 });
下面是html代码

            <div id="header" style="width:180px;"><span style="background-color:#FFFFFF">img</span></div><br />
        <br />

        <div id="container">



        <table width="200" id="shoppingCart2" border="1">
        <tr>
        <td>test1</td>
        <td id="t1" class="time"> td1&nbsp;</td>
        <td id="t2" class="time">td2&nbsp;</td>
        </tr>
        <tr>
        <td>test2</td>
        <td class="time">&nbsp;</td>
        <td class="time">&nbsp;</td>
        </tr>
        <tr>
        <td>test3</td>
        <td class="time">&nbsp;</td>
        <td class="time">&nbsp;</td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        </table>
        </div>
img

测试1 td1 td2 测试2 测试3
我使用的脚本是:


当拖动“img”时,它下降到每行的第一个td。我不能在每行的第二和第三个tds中删除这个。然后我需要在丢弃后获取相应的td id。请帮帮我

你只允许把东西放在桌上#购物车上,而不允许放在td上 改用“#购物车2 td”


根据以下内容更改脚本

$(function () {

$("#header").draggable({
    helper: "clone",
    cursor: 'move',
    tolerance: 'fit',
    containment: '#container'//use #container instead  of #shoppingCart2
});

$("#shoppingCart2 td").droppable({//use  #shoppingCart2 instead of #shoppingCart2 td

    drop: function (e, ui) {

        if ($(ui.draggable)[0].id != "") {
            x = ui.helper.clone();
            ui.helper.remove();
            x.draggable({
                helper: 'original',
                containment: '#container',//use #container instead  of #shoppingCart2
                tolerance: 'fit'
            });

            x.appendTo('#container');
        }

    }
});

});
工作

$(function () {

$("#header").draggable({
    helper: "clone",
    cursor: 'move',
    tolerance: 'fit',
    containment: '#container'//use #container instead  of #shoppingCart2
});

$("#shoppingCart2 td").droppable({//use  #shoppingCart2 instead of #shoppingCart2 td

    drop: function (e, ui) {

        if ($(ui.draggable)[0].id != "") {
            x = ui.helper.clone();
            ui.helper.remove();
            x.draggable({
                helper: 'original',
                containment: '#container',//use #container instead  of #shoppingCart2
                tolerance: 'fit'
            });

            x.appendTo('#container');
        }

    }
});

});