【发布时间】:2016-02-15 05:26:50
【问题描述】:
我有如下图所示的 JQuery 表
单击“操作”列中的V 链接文本后,我想提醒ProductID
<table id="productTable">
<thead>
<tr>
<th>ProductID</th>
<th>TitleEN</th>
<th>TypeEN</th>
<th>ModifiedDate</th>
<th>Actions</th>
</tr>
</thead>
</table>
@* Load datatable css *@
<link href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet" />
@section Scripts{
@* Load DataTable js here *@
<script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$("#productTable").DataTable({
"info": false,
"processing": true,
"serverSide": true,
"filter": false,
"orderMulti": false,
"ajax": {
"url": "/Home/LoadProductData",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "Product_ID", "name": "Product_ID", "autoWidth": true },
{ "data": "Product_Title_EN", "name": "Product_Title_EN", "autoWidth": true },
{ "data": "Product_Type_EN", "name": "Product_Type_EN", "autoWidth": true },
{ "data": "ModifiedDate", "name": "ModifiedDate", "autoWidth": true },
{
data: null,
className: "center",
defaultContent: '<a href="" class="editor_view"> V </a>'
}
]
});
});
$('#editor_view').on('click', 'a.editor_view', function (e) {
alert($("data-Product_ID").val());
});
</script>
}
目前我是这样提醒它的
alert($("data-Product_ID").val());
但它无法获取该 ID,我可以这样做吗?
这是表格行的html
<tr class="even" role="row">
<td class="sorting_1">02</td>
<td>Current Accounts</td>
<td>Assets</td>
<td></td>
<td class=" center">
<a class="editor_view" href="#"> V </a>
</td>
【问题讨论】:
-
$(this).closest('tr').find("#data-product_ID").val()
-
不能确定没有看到典型行的实际 html,但
$(this).closest('tr').find('td').eq(0).text();应该得到它 -
@MayankVadiya 刷新页面不起作用
-
注意它必须是
$('.editor_view').click(function() { ... } -
您是否也按照我上次的评论更改了选择器。如果这不起作用,您需要显示为一行生成的实际 html(也应该是
<a href="#" ....>)
标签: javascript jquery asp.net-mvc razor datatables