gpt4 book ai didi

javascript - 如何使用 jQUery 中的数据属性更新表中的数据

转载 作者:行者123 更新时间:2023-11-27 22:32:27 25 4
gpt4 key购买 nike

我在 html 中有这个表,我需要使用数据用户 ID 更新用户,我对此进行了操作,但此函数没有更改网页中的任何内容。

这里,我有 data-userid 的 html 表代码:

 <table id="tblList">
<tbody id="someTest">
<tr data-userid="801992084067"></tr>
<tr data-userid="451207954179"></tr>
<tr data-userid="310896831399"></tr>
<tr data-userid="863939754980"></tr>
<tr data-userid="1123542226482"></tr>
</tbody>
</table>

这里我有更新功能。

function updateUser(userId, user) {

var foundUser = findUser(userId);


foundUser.username = user.username;
foundUser.level = user.level;
foundUser.registrationStatus = user.registrationStatus;
foundUser.registrationDate = user.registrationDate;


for(var i = 1; i<userId.length; i++){
$("#someTest tr[data-userid = 'userid " + userId[i] + "']").each(function () {
// if (rowId === userId) {

var table = $('#tblList');

var row = "<tr data-userid=" + foundUser.id + ">"
+ " <td>"
+ " <img src='resources/img/edit.png' alt='Edit' class='btnEdit'/>"
+ " <img src='resources/img/delete.png' alt='deleteUser' class='btnDelete'/>"
+ "</td>"
+ " <td>" + foundUser.username + "</td>"
+ " <td>" + foundUser.level + "</td>"
+ " <td>" + foundUser.registrationStatus + "</td>"
+ " <td>" + foundUser.registrationDate + "</td>"
+ "</tr>";
table.append(row);
// }
});
}
hidePopup();
}

我的问题如下:在 updateUser 函数中该怎么做,因为当我更改用户时,要在浏览器中查看该更改?

最佳答案

试试这个

function updateUser(userId, user) {

var foundUser = findUser(userId);


foundUser.username = user.username;
foundUser.level = user.level;
foundUser.registrationStatus = user.registrationStatus;
foundUser.registrationDate = user.registrationDate;

var row = " <td>"
+ " <img src='resources/img/edit.png' alt='Edit' class='btnEdit'/>"
+ " <img src='resources/img/delete.png' alt='deleteUser' class='btnDelete'/>"
+ "</td>"
+ " <td>" + foundUser.username + "</td>"
+ " <td>" + foundUser.level + "</td>"
+ " <td>" + foundUser.registrationStatus + "</td>"
+ " <td>" + foundUser.registrationDate + "</td>";


$("#someTest tr[data-userid = '" + userId + "']").html(row)
hidePopup();
}

关于javascript - 如何使用 jQUery 中的数据属性更新表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39428502/

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