gpt4 book ai didi

javascript - 单击 td 时转换为下拉框并将更改保存到数据库

转载 作者:行者123 更新时间:2023-11-30 21:30:18 25 4
gpt4 key购买 nike

我有一个脚本,当单击 td(表数据)时会显示一个下拉框。它包含选项“X”和“O”。

我的 html 表包含我的数据库中的数据。我的客户想要对数据进行前端编辑,因为这对他们来说很容易。所以我将 td 转换为下拉列表,以便他们可以轻松发表评论。但是如何将用户在表中所做的更改保存到数据库。

这是我制作 td 下拉框的脚本:

$(document).on('click', 'td', function() { ////---make td transform to dropdown list box when click---///
if($(this).find('select').length == 0) {
$(this).empty(); //clears out current text in the table
$(this).append('<select><option></option><option style="font-size:20px;">X <option style="font-size:20px;">O</select>');
}
});

最佳答案

将名称和类别添加到您的选择框

$(document).on('click', 'td', function() { 
if($(this).find('select').length == 0)
{
$(this).empty(); //clears out current text in the table
$(this).append('<select class="selectbox" name="selectbox"><option></option><option
style="font-size:20px;" value="X">X <option value="0" style="font-size:20px;">O</select>');
}
});

并创建一个 jquery 更改事件,尝试这样的事情

 $(document).on('change', '.selectbox', function() { 
$.ajax({
type: 'POST',
crossDomain: true,
data: {
data_value: this.value,
},
url: 'your_url_to_update_to_db.php',
success: function (data)
{
//do Something
},
});
});

关于javascript - 单击 td 时转换为下拉框并将更改保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56573996/

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