如何在拖动数据时获取td值?我需要帮助,谢谢。
这里是javascript:
<script>
$(function() {
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connected"
});
$( "#sortable1, #sortable2" ).disableSelection();
$( "#sortable1, #sortable2" ).sortable({ //here i want to alert the value when stop dragging
stop: function( event, ui ) {
var val1 = $("td").innerHTML;
alert(val1);
}
});
});
</script>
这里是html代码:
<?php if(!empty($query)){?>
<table id="todo" name="todo" class="table table-bordered" style='width:150px'><thead>
<tr>
<th style="text-align:center;background-color:#eee">TO DO</th>
</tr>
</thead>
<tbody id="sortable1" class="connected">
<?php foreach($query as $row):?>
<tr>
<td style="width:150px;background-color:#eee" id="<?php echo $row->list;?>" name="<?php echo $row->list;?>" value="<?php echo $row->list;?>"><?php echo $row->list;?></td>
</tr>
<?php endforeach;}?>
</tbody>
</table>
<table id="today" name="today" class="table table-bordered" style='width:150px'>
<thead>
<tr>
<th class="ui-state-highlight" style="text-align:center">TODAY</th>
</tr>
</thead>
<tbody id="sortable2" class="connected">
</tbody>
</table>
我不知道我的错在哪里。请给我一个答案。
答案 0 :(得分:0)
替换
var val1 = $("td").first().html();//first() to ensure only
答案 1 :(得分:0)
在stop:
内部事件监听器中,尝试以下内容:
stop: function( event, ui ) {
var val1 = $(ui.item).html(); //ui.item is a jQuery object representing the current dragged element
alert(val1);
}
答案 2 :(得分:-1)