我已经使用 JQuery 动态地在表中的每一行创建了更新按钮,成功编辑了表,但我不知道如何调用 php 函数来更新数据库,
我使用陪审团作为
$(document).ready(function () {
$('.editbtn').click(function() {
var $this = $(this);
var tds = $this.closest('tr').find('td').filter(function() {
return $(this).find('.editbtn').length === 0;
});
if ($this.html() === 'Edit') {
$this.html('Save');
tds.prop('contenteditable', true);
} else {
$this.html('Edit');
tds.prop('contenteditable', false);
}
});
问题: 如何将行id传递给jquery然后update.php页面, 我正在等待你的帮助,我已经谷歌了很多次但无法解决我的问题
最佳答案
我更喜欢将编辑按钮上的行的 id 设置为属性,当您单击编辑时,您可以通过此元素选择 id。检查下面的代码例如:
//Here 1 is id of row which you want to edit
<button class="editbtn" data-id="1">Edit Row</button>
您可以在 editbtn 类上单击获取 id,如下所示:
$('.editbtn').click(function() {
let rowId = $(this).data("id");
});
并且要保存更新的值,需要调用ajax或者需要提交表单。您需要在ajax请求中传递所有数据,包括行id、其他字段值。我更喜欢使用 Ajax,因为它不会加载您的页面,而且 UI 看起来会更好。
希望对您有帮助。
关于php - 编辑 html 表行并使用 php 将其更新到 mysql 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54615833/