javascript - 使用 javascript 和 json 加载表格时如何为按钮分配多个值

标签 javascript html json

在下面的代码中,我使用了 json 数组(pedingPLT)将数据加载到下面的 html 表中。这里每个表数据都有一个值。在特定的表数据中,我包含了一个按钮。那么是否有可能为按钮分配多个值(*********),我的意思是通过使用数组。请帮助我

   function TSC_document_status_list_table_for_tsc_portal() {
        var tableData;
        $.post("model/tscAdminView.php", {action: 'TSC_document_status_list_table_for_tsc_portal'}, function (e) {
            if (e === undefined || e.length === 0 || e === null) {
                tableData = '<tr class="error"><td colspan="4"> No Data Found in database </td></tr>';
                $('#TSC_document_status_list_table_for_tsc_portal tbody').html('').append(tableData);
            } else {
                $.each(e, function (index, pedingPLT) {
                    index++;
                    tableData += '<tr>';
                    tableData += '<td>' + index + '</td>';
                    tableData += '<td>' + pedingPLT.document_id + '</td>';
                    tableData += '<td>' + pedingPLT.tsc_accepted_Or_Created_date +'</td>';
                    tableData += '<td>' + pedingPLT.total_allocated_days + ' days' + '</td>';
                    tableData += '<td>' + pedingPLT.Expired_date  + '</td>';
                    tableData += '<td> <button class="btn btn-sm btn-alt m-r-5 delete_selected_employee" value="' +  ********  + '"><i class="fa fa-trash-o fa-lg"></i>&nbsp;</button>' + pedingPLT.total_quantity +'</td>';
                    tableData += '<td>' + pedingPLT.Completed_phone_list + '</td>';
                    tableData += '<td>' + pedingPLT.peding_phone_list + '</td>';
                    tableData += '</tr>';
                });
                //Load Json Data to Table
                $('#TSC_document_status_list_table_for_tsc_portal tbody').html('').append(tableData);
            }
        }, "json");
    }

enter image description here

最佳答案

按钮的 value 属性的类型为“text”( source ),因此无法向其添加多个值。

也就是说,您可以自由地将其中的 JSON 字符串字符串化为值,并在需要时解析它:

JSON.stringify()

(方法文档:JSON.stringify)

关于javascript - 使用 javascript 和 json 加载表格时如何为按钮分配多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45372457/

相关文章:

javascript - 根据不同的按钮点击打开不同的iframe

jquery - 根据类和标题隐藏 SPAN 标签上的文本

html - 如何使用 font-face 缩小 CSS

java - 在 Java 中将 JSON 对象转换为 util.Date

java - 在java中更快地解析json

javascript - 删除重复项并合并 JSON 对象

javascript - 将字符串中的点从charcode转换为十六进制(javascript)

javascript - 选择框的特殊行为(需要您的意见)

javascript 旋转器/无 jQuery

javascript - django View 可以显示在灯箱中吗?