gpt4 book ai didi

javascript - 尝试更新 DOM 中的 HTML 表值时出现错误

转载 作者:行者123 更新时间:2023-12-03 06:00:52 25 4
gpt4 key购买 nike

我正在尝试为表中的值实现简单的更新功能。我有一个编辑按钮,它会触发一个模式,我可以在其中编辑值并保存它们。为了在 DOM 中立即更新值,我在保存时使用以下 jquery 代码:

 $('#lblEditDeleteProducts').find("tr .nameDom").text("new val");
$('#lblEditDeleteProducts').find("tr .brandDom").text("new val");
$('#lblEditDeleteProducts').find("tr .priceDom").text("new val");

问题是,使用此代码而不是表中的一行,所有行都会使用“新值”进行更新。我对 jquery 很陌生,我不知道如何解决这个问题,所以任何帮助将不胜感激。

这是我的表结构:

enter image description here

最佳答案

由于您的 HTML 代码信息不多

var selectedTR;

$("#lblEditDeleteProducts tr").click(function(){
selectedTR=$(this);
//init your modal pop up here or do it globally
})

假设保存按钮的ID#save

$("#save").click(function(){
selectedTR.find(".nameDom").text("new val"); // get relative value from the mdoal input
selectedTR.find(".brandDom").text("new val");
selectedTR.find(".priceDom").text("new val");
})

如果您有兴趣,也可以使用此插件(高级功能)datatable inline edit

关于javascript - 尝试更新 DOM 中的 HTML 表值时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39753956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com