表格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/我想修改代码进行编辑
你可以用jQuery这样做:
$("#frm-example").submit(function() {
var form = $(this);
$("#table3 :checkbox:checked").each(function() {
form.append($("<input>", {
type: "hidden",
name: "id[]",
value: this.id
}));
});
});