这是用户界面
我想要的是,当用户单击任何“批准”或“拒绝”按钮时,我想获取该特定行的“备注”值。
这是我到目前为止的cshtml代码
@model IEnumerable<HrmsMvc.Models.DataContext.LeaveRecord>
@{
using (Html.BeginForm())
{
<fieldset>
<legend>Approve Leave</legend>
<div style="font-family: Verdana; font-size: 10px;"overflow-scrolling: auto>
@{
if (Model != null)
{
<table>
<thead>
<tr>
<th>Apply Date</th>
<th>Name</th>
<th>From</th>
<th>To</th>
<th>Type</th>
<th>Reason</th>
<th>Status</th>
<th>Remarks</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@{
try
{
foreach (var leave in Model)
{
<tr>
<td>@Html.LabelForModel(leave.ApplicationDate.Value.ToString("dd-MMM-yyyy"))</td>
<td>@Html.LabelForModel(leave.EmployeeInfo.FullName)</td>
<td>@Html.LabelForModel(leave.EffectiveFrom.Value.ToString("dd-MMM-yyyy"))</td>
<td>@Html.LabelForModel(leave.EffectiveTo.Value.ToString("dd-MMM-yyyy"))</td>
<td>@Html.LabelForModel(leave.LeaveType)</td>
<td>@Html.LabelForModel(leave.Reason)</td>
<td>@Html.LabelForModel(leave.LeaveStatus)</td>
<td>
<input type="text" style="width: 200px;" data-text-id="@leave.LeaveRecordID" />
</td>
<td style="display: block; width: 200px;">
<input type="submit" style="width: 80px; height: 25px; background-color: greenyellow;" value="Approve" data-id="@leave.LeaveRecordID" />
<input type="submit" style="width: 80px; height: 25px; background-color: lightcoral;" value="Reject" data-id="@leave.LeaveRecordID" />
</td>
</tr>
}
}
catch
{
}
}
</tbody>
</table>
}
}
</div>
</fieldset>
}
}
@section scripts
{
<script type="text/javascript">
var leaveRecordId = 0;
var applicantEmid = "";
var leaveType = "";
var applicationDate = "";
var leaveStatus = "Pending";
var reason = "";
var entryEmid = "";
var entryDate = "";
var lastUpdateEmid = "";
var lastUpdateDate = "";
var effectiveFrom = "";
var effectiveTo = "";
$(document).ready(function () {
// here I want to get the button and the related remarks data
});
});
</script>
}
每个按钮都有一个 data-id 属性,其中包含相关的 RecordID。我不明白如何获得这个或从哪里开始?
最佳答案
只需给“批准”和“拒绝”按钮类“btn”并尝试以下答案:
$(.btn).click(function(){
var textvalue = $(this).closest('tr').find('td').eq(7).find('input[type=text]').val();
});
或者,如果您想在单击时获取按钮的RecordID
,请执行以下操作:
$(.btn).click(function(){
var id = $(this).attr("data-id");
});
关于javascript - 如何在jquery表中找到与单击的按钮相关的<tr>数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25421258/