【发布时间】:2014-03-27 14:11:14
【问题描述】:
我正在尝试解决jquery的可拖动问题,有代码可以从数据库中检索信息,每个信息都显示在数据库每一行的每个BOX中。
draggable 可以正常工作,拖动到删除框时也可以正常工作。
每个 div 框都带有一个名为“remove”的按钮,该按钮用于删除单个 div 框(不是所有 div 框同时)。问题是按下按钮删除每个单独的 div 框并没有删除,只允许我删除第一个框而不是其余的框。请查看 jquery 代码,因为您可以看到它所说的行
$(this).closest('.draggable').remove();
这条线不工作...
任何其他想法我该如何解决这个问题,让我可以让删除按钮工作!
这里是php代码。
<?php
include('dbcon.php');
$product_id=$_POST['selector'];
$N = count($product_id);
for($i=0; $i < $N; $i++)
{
$result = mysql_query("SELECT * FROM product where product_id='$product_id[$i]'");
while($row = mysql_fetch_array($result))
{ ?>
<div class="draggable" id="draggable[]" style="width:300px; height:200px">
<div class="thumbnail">
<div id="remove"><a class="button" href="#"><span class="search-icon">remove</span></a></div>
<div class="control-group">
<label class="control-label" for="inputEmail">product id</label>
<div class="controls">
<input name="member_id[]" type="hidden" value="<?php echo $row['product_id'] ?>" />
<input name="firstname[]" type="text" value="<?php echo $row['product_name'] ?>" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">product category</label>
<div class="controls">
<input name="lastname[]" type="text" value="<?php echo $row['product_category'] ?>" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">product price</label>
<div class="controls">
<input name="middlename[]" type="text" value="<?php echo $row['product_price'] ?>" />
</div>
</div>
</div></div>
<br>
<?php
}
}
?>
在 jquery 中 ....
$(function() {
$('.draggable').draggable();
$('#trash').droppable({
over: function(event, ui) {
$(ui.draggable).remove();
}
});
$('#remove').click(function(){
$(this).closest('.draggable').remove();
});
});
【问题讨论】: