【问题标题】:How to edit data array to checkbox with javascript如何使用javascript将数据数组编辑为复选框
【发布时间】:2018-06-05 14:38:15
【问题描述】:

表格 HTML

 <table id="example3" class="display" cellspacing="0" width="100%">
    <thead>
      <tr>
         <th></th>
         <th>Nama</th>
         <th>Unit</th>
      </tr>
    </thead>
 </table>

Javascript 标题选择行

$('#frm-example').on('submit', function(e){ //on submit
    var form = this;
    var rows_selected = table3.column(0).checkboxes.selected();

        // Iterate over all selected checkboxes
        $.each(rows_selected, function(index, rowId){
           // Create a hidden element 
           $(form).append(
              $('<input>')
              .attr('type', 'hidden')
              .attr('name', 'id[]')
              .val(rowId)
           );
       });

我的数据库

+-----------+--------------+---------------+-----------+-------------+-----------+------------------------------+---------------------+
| id_survey | judul_survey | status_survey | id_target | id_kategori | responden | detail_target                | tgl_survey          |
+-----------+--------------+---------------+-----------+-------------+-----------+------------------------------+---------------------+
|       130 | tes          | terbit        |         3 |           2 |         2 | 198411162009101002,H76215021 | 2017-12-19 15:08:35 |
+-----------+--------------+---------------+-----------+-------------+-----------+------------------------------+---------------------+
1 row in set (0.07 sec)

detail_kategori 字段中的数据复选框,我如何将其放入表单复选框以进行更新?

好的,我从这里得到代码复选框https://jsfiddle.net/gyrocode/07Lrpqm7/ 我要修改代码来编辑

【问题讨论】:

  • 不知道你在问什么
  • 好的,我从这里jsfiddle.net/gyrocode/07Lrpqm7 获取代码复选框。我要修改代码来编辑
  • 您要编辑选定行的值...?
  • 是的先生,我想编辑选定的行
  • 您显示的 HTML 中没有复选框。

标签: javascript php jquery html checkbox


【解决方案1】:

你可以用 jQuery 做到这一点:

$("#frm-example").submit(function() {
    var form = $(this);
    $("#table3 :checkbox:checked").each(function() {
        form.append($("<input>", {
            type: "hidden",
            name: "id[]",
            value: this.id
        }));
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-18
    • 2017-11-20
    • 2019-09-21
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多