将ID分配给asp.net Javascript按钮
在我的代码中,我有一个用于输入数据的按钮,但如下图所示,它只读取与按钮无关的第一行 我相信这是因为没有为每一行分配按钮id 如何将我的id从每一行转到我的按钮 我的身份证是身份证信息将ID分配给asp.net Javascript按钮,javascript,html,jquery,asp.net,asp.net-mvc,Javascript,Html,Jquery,Asp.net,Asp.net Mvc,在我的代码中,我有一个用于输入数据的按钮,但如下图所示,它只读取与按钮无关的第一行 我相信这是因为没有为每一行分配按钮id 如何将我的id从每一行转到我的按钮 我的身份证是身份证信息 <td> <button class="btn ToEditbtn" ><span class="fa fa-plus-square" aria-hidden="true"></span>Edi
<td>
<button class="btn ToEditbtn" ><span class="fa fa-plus-square" aria-hidden="true"></span>Edit</button>
<button class="btn Editbtn" style="display:none"><span class="fa fa-plus-square-o" aria-hidden="true">Save</span></button>
</td>
@section scripts{
<script>
$(function () {
$("#ordertable").on("click", ".ToEditbtn", function () {
$(this).hide();
var currenttr = $(this).closest("tr");
currenttr.find(".Editbtn").show();
currenttr.find(".Status").prop("disabled", false);
currenttr.find(".Obs").prop("disabled", false);
});
//update
$("#ordertable").on("click", ".Editbtn", function () {
var status = new Object();
status.ID_Info = $(".ID_Info").val();
status.Status = $(".Status").val();
status.Obs = $(".Obs").val();
...
<script>
}
编辑
拯救
@节脚本{
$(函数(){
$(“#ordertable”)。在(“单击”上,“.ToEditbtn”,函数(){
$(this.hide();
var currenttr=$(此);
currenttr.find(“.Editbtn”).show();
currenttr.find(“.Status”).prop(“disabled”,false);
currenttr.find(“.Obs”).prop(“已禁用”,false);
});
//更新
$(“#ordertable”)。在(“click”、“.Editbtn”上,函数(){
var status=新对象();
status.ID_Info=$(“.ID_Info”).val();
status.status=$(“.status”).val();
status.Obs=$(“.Obs”).val();
...
}
谢谢当您点击
保存
按钮时,您正在使用$(“.ID\u Info”)
获取值,这不会给您提供所需值,因为存在同名的多个类。因此,若要仅针对所需值,您可以使用$(this)。最近('tr')。查找('valueyouneedtofind')…
,即:
$("#ordertable").on("click", ".Editbtn", function() {
var status = new Object();
status.ID_Info = $(this).closest('tr').find(".ID_Info").val();
status.Status = $(this).closest('tr').find(".Status").val();
status.Obs = $(this).closest('tr').find(".Obs").val();
//other codes
})
这可能会有帮助,同样的问题和解决方案也适用于他。没错,谢谢,顺便问一下,既然我收到了数据,你能帮我保存吗?因为我使用db.savechanges,但它不记录。嗨,我会帮忙的,但是,我在asp方面的知识有限:)