簡體   English   中英

使用鼠標向上事件獲取表ID

[英]get table id using mouse up event

我已經使用拖放表的行元素創建了一個應用程序。 在這種情況下,我想獲取放置的元素ID(即放置的表ID)。 我嘗試了鼠標上移事件。 但我無法得到正確的答案。

我正在使用tablednd插件。

  1. 我有兩張桌子。 這樣,我將把tr從一個表拖放到另一個表。
  2. 在那我想刪除表ID。
<script src="<?php echo base_url(); ?>assets/js/drag/jquery.tablednd_0_5.js" type="text/javascript"></script>
 <script type="text/javascript">
    $(document).ready(function () {
        $(".tbl_repeat tbody").tableDnD({
            onDrop: function (table, row) {
                var orders = $.tableDnD.serialize();
                //console.log(orders);
                // alert(table.id);
                //alert($('td').closest('table')[2].id);
                //$.post('<?php echo base_url(); ?>dashboard/order_update', { orders : orders });
            }
        });
</script>

我正在使用此功能來獲取刪除的表ID:

document.body.onmouseup = function (e) {
    e = e || window.event;
    var elementId = (e.target || e.srcElement).id;
    // call your re-create function
    recreate(elementId);
    // ...
}

function recreate(id) {
    alert(id);
}

HTML

 <table id="tbl1" class="table-striped table-bordered table-responsive tbl_repeat" style="width:100%;">
<tbody id="hai1">
<tr>
</tr>
</tbody>
  </table>

<table id="tbl2" class="table-striped table-bordered table-responsive tbl_repeat" style="width:100%;">
<tbody id="hai1">
<tr>
</tr>
</tbody>
  </table>

<table id="tbl3" class="table-striped table-bordered table-responsive tbl_repeat" style="width:100%;">
<tbody id="hai1">
<tr>
</tr>
</tbody>
  </table>

提前致謝。

請查看您是否從此示例代碼中獲得幫助

 $(document).ready(function () { $('.ClsTBL').hover( function () { console.log('hovering on', $(this).attr('id')); }, // You can add your functions function () { } ); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <html> <head></head> <body> <div> <table id="MyTbl1" class="ClsTBL"> <tr> <td>Test</td> <td>Test 1</td> </tr> </table> <table id="MyTbl2" class="ClsTBL"> <tr> <td>Test</td> <td>Test 1</td> </tr> </table> </div> </body> </html> 

你可以用這個

$(".tbl_repeat tbody").tableDnD({
            onDrop: function (table, row) {
               var tableId = $(this).parents('table').attr('id');
               console.log(tableId);
               var orders = $.tableDnD.serialize();

            }
        });

karthick像這樣

   onDrop: function (table, row) {
            var orders = $.tableDnD.serialize();
            var t=$(table);
            console.log(t.attr('id'));
            //console.log(orders);
            // alert(table.id);
            //alert($('td').closest('table')[2].id);
            //$.post('<?php echo base_url(); ?>dashboard/order_update', { orders : orders });
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM