【发布时间】:2019-08-10 12:31:25
【问题描述】:
我有一个带有表格的屏幕,其中可以包含任意数量的输入字段,具体取决于限制显示记录的过滤器。每个输入字段旁边是一个链接,用户将点击该链接以将该记录的数据保存到数据库中。我想要做的是当用户单击任何给定行的保存按钮时,我希望光标移动到下一行的下一个输入字段(如果存在)。我知道回发会删除我当前的光标位置,所以我一直在尝试将它保存在一个没有运气的变量中。任何帮助,将不胜感激。 根据我的理解,javascript 应该获取元素并将其存储到隐藏字段中。我得到的结果是我网站的 URL。只有当我将该字段存储到 test2 字段中时,我才能获得存储的实际元素。我应该尝试以某种方式获取元素的坐标并存储它吗?但如果我这样做了,我将如何获得表格中可用的下一个输入字段?
下面的表定义和 JavaScript:
$('.checklistequipmentinsertlink').mousedown(function () {
document.getElementById('savedelement').value = document.querySelector("a:active");
var test2 = document.querySelector("a:active");
var test = document.getElementById('savedelement').value;
});
<div id="scrollbox" class="tablediv" onscroll="javascript:document.getElementById('scrollposition').value = this.scrollTop">
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayName("Equipment/Location")
</th>
<th>
@Html.DisplayName("Category")
</th>
<th>
@Html.DisplayName("Expected Count/Checkoff")
</th>
<th>
@Html.DisplayName("Actual Count/Checkoff")
</th>
</tr>
</thead>
<tbody>
@if (Model.postChecklistEqupmentList != null)
{
@foreach (var item in Model.postChecklistEqupmentList)
{
<tr>
<td class="hiddentd">
@Html.DisplayFor(modelitem => item.Checklist_ID)
</td>
<td class="hiddentd">
@Html.DisplayFor(modelitem => item.Checklist_Equipment_ID)
</td>
<td>
@Html.DisplayFor(modelitem => item.Checklist_Equipment_Desc)
</td>
<td>
@Html.DisplayFor(modelitem => item.Equipment_Category_Desc)
</td>
<td id="expectedcount">
@Html.DisplayFor(modelitem => item.Equipment_Count_Or_Checked)
</td>
<td>
@Html.TextBoxFor(modelitem => item.Actual_Count_Or_Checked, new
{
htmlAttributes = new
{
@class = "form-control"
},
autofocus = "autofocus"
})
</td>
<td>
<a href="#" class="checklistequipmentinsertlink">Save</a>
</td>
</tr>
}
}
</tbody>
</table>
</div>
【问题讨论】:
标签: javascript c# asp.net postback