JQuery reading table row value
I have tried different ways on the net but nothing is working. Below is my table.
I want the values of ID and inputbox. Below is my table.
<a id="procressGrid" class="deletePageLink" href="#" title="Delete Menu" >Process Grid</a>
<div class="gridDiv">
<table class="gridTable" cellspacing="0" cellpadding="0">
<tr class="gridTitleRow">
<td class="numberingTd width36"> </td>
<td class="iconLink width60">Sort Order</td>
<td class="iconLink widthAuto">Display Name</td>
<td class="iconLink widthAuto">Url Name</td>
<td class="iconLink widthAuto">Active</td>
</tr>
@foreach (var grp in distMenu)
{
@Html.Hidden("Id", @grp.Id)
<tr class="gridRow">
开发者_如何学运维 <td class="numberingTd">@(num++)</td>
<td class="cellTd"><input name="code" class="numberField" type="text" value="@grp.Id" /></td>
<td class="cellTd">@grp.DisplayName</td>
<td class="cellTd ">@grp.UrlName Us</td>
<td class="cellTd ">@grp.Active</td>
</tr>
}
</table>
</div>
HTML Element's ID's should be unique. Hence changed the HTML rendering you were using. Check the JS function getIDs to see how to get the ID's as an array.
<script type="text/javascript">
function getIDs(){
var dataArray = [];
$.each($(".gridTable tr:not(.gridTitleRow)"), function(a, b){
var id = $("input.idField", b).val();
var code = $("input[name='code']", b).val();
dataArray.push({
"id": id,
"code": code
})
});
return dataArray;
}
</script>
<a id="procressGrid" class="deletePageLink" href="#" title="Delete Menu" >Process Grid</a>
<div class="gridDiv">
<table class="gridTable" cellspacing="0" cellpadding="0">
<tr class="gridTitleRow">
<td class="numberingTd width36"> </td>
<td class="iconLink width60">Sort Order</td>
<td class="iconLink widthAuto">Display Name</td>
<td class="iconLink widthAuto">Url Name</td>
<td class="iconLink widthAuto">Active</td>
</tr>
@foreach (var grp in distMenu)
{
<tr class="gridRow">
<td class="numberingTd">
@(num++)
@Html.Hidden("Id_" + num, @grp.Id, new{class="idField"})
</td>
<td class="cellTd"><input name="code" class="numberField" type="text" value="@grp.Id" /></td>
<td class="cellTd">@grp.DisplayName</td>
<td class="cellTd ">@grp.UrlName Us</td>
<td class="cellTd ">@grp.Active</td>
</tr>
}
</table>
</div>
精彩评论