簡體   English   中英

單擊時獲取行的 id

[英]get id of the row on click

伙計們,我正在使用 jqgrid ......我想在點擊圖像時獲得該行的 id 而不先選擇整行......這是我的代碼

 <script type="text/javascript"> $(document).ready(function() { $("#jqGrid").jqGrid({ url: 'data.json', datatype: "json", styleUI: "Bootstrap", colModel: [{ label: 'Order ID', name: 'OrderID', key: true, width: 75, hidden: true }, { label: 'From Date', name: 'FromDate', width: 150, editable: true, edittype: "text", id: "ui-datepicker-div", editoptions: { dataInit: function(element) { $(element).datepicker({ autoclose: true, format: 'yyyy-mm-dd', orientation: 'auto bottom' }); }, }, }, { label: 'To Date', name: 'ToDate', width: 150, editable: true, edittype: "text", editoptions: { dataInit: function(element) { $(element).datepicker({ autoclose: true, format: 'yyyy-mm-dd', orientation: 'auto bottom' }); }, }, }, { label: 'Customer ID', name: 'CustomerID', width: 150 }, { label: 'Ship Name', name: 'ShipName', width: 200 }, { label: 'Row Data', name: 'RowData', align: 'center', formatter: function() { return "<img src='resources/icon.jpg' onclick='OpenDialog()' alt='Data Row' />"; width = 15; } }, ], loadonce: true, ...... }); }); ........... function OpenDialog() { var result = ""; var grid = $("#jqGrid"); var rowKey = grid.getGridParam("selrow"); rowData = grid.getLocalRow(rowKey); for (var item in rowData) { if (item == 'RowData') { break; } result += rowData[item] + ', '; } alert(result); }

任何幫助請如何僅單擊圖像即可獲取行的 id ??.. 非常感謝 .. 在此先感謝

使用這個 html:

onclick='OpenDialog(this)'

並在 OpenDialog 中使用最接近的 jquery 方法:

function OpenDialog(element) {
   var id = $(element).closest('tr').attr('id');
   ...
}

暫無
暫無

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

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