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 </td>
<td id="t2" class="time">td2 </td>
</tr>
<tr>
<td>test2</td>
<td class="time"> </td>
<td class="time"> </td>
</tr>
<tr>
<td>test3</td>
<td class="time"> </td>
<td class="time"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </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');
}
}
});
});