How to get the td value when the data dragged? I need help, thankyou.
Here the 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>
and here the html code:
<?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>
I don't know where my fault. Please give me an answers.
在这里替换
var val1 = $("td").first().html();//first() to ensure only
Inside stop:
event listener, try following thing:
stop: function( event, ui ) {
var val1 = $(ui.item).html(); //ui.item is a jQuery object representing the current dragged element
alert(val1);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.