我无法在以下代码中获取数据属性 (data-scd-editUrl) 的值;
@foreach (var item in Model)
{
<tr data-pkey="@item.TradeId">
<td style="text-align:left;vertical-align:top;height:20px;">
<div style="width:100%;height:100%;overflow:hidden;">
@Html.DisplayFor(modelItem => item.TradeName)
</div>
</td>
<td class="rowControl hidden" style="text-align:left;vertical-align:top;height:20px;">
<div style="width:100%;height:100%;overflow:hidden;">
<img src="@Url.Content("~/Images/Pencil.ico")" style="height:15px;width:15px" title="edit" alt="edit" class="makeRowEditable"
data-scd-editUrl="@Url.Action("Edit", new { id = item.TradeId})"/> |
<img src="@Url.Content("~/Images/icon-delete.gif")" style="height:15px;width:15px" title="delete" alt="delete" class="deleteRow"
data-scd-editUrl="@Url.Action("Delete", new { id = item.TradeId})"/>
</div>
</td>
</tr>
}
Jquery是;
gridContext.delegate('.makeRowEditable', 'click', function (e) {
var editUrl = $('this').data("scd-editUrl");
var row = $(this).parents('tr');
makeRowEditable(row, editUrl);
e.preventDefault();
});
使用委托是因为此代码是网格的一行,并且通过 Ajax 为新页面动态重新加载。我在上面的代码中放了一个断点,editUrl 为空。为什么会这样?