我有jQuery獲取多個複選框的值。jQuery通過多個複選框值使用Ajax的PHP到
您可以參考的演示here
爲jQuery的功能是確定的,當我們勾選複選框,然後我們可以看到我們選擇基於btnUpdate點擊後數據-ID。
但現在我想通過並將其存儲到數據庫使用Ajax的PHP。 所以示例輸出,
1 -> read
1 -> update
2 -> update
然後將其保存到數據庫中的表:
ID | chkStatus
1 | read
1 | update
2 | update
下面是HTML
<table>
<tr>
<th>Nama</th>
<th>Create</th>
<th>Read</th>
<th>Update</th>
<th>Delete</th>
</tr>
<tr>
<td>coba</td>
<td><input type="checkbox" data-id="1" data-tipe="create"></td>
<td><input type="checkbox" data-id="1" data-tipe="read"></td>
<td><input type="checkbox" data-id="1" data-tipe="update"></td>
<td><input type="checkbox" data-id="1" data-tipe="delete"></td>
</tr>
<tr>
<td>coba 2</td>
<td><input type="checkbox" data-id="2" data-tipe="create"></td>
<td><input type="checkbox" data-id="2" data-tipe="read"></td>
<td><input type="checkbox" data-id="2" data-tipe="update"></td>
<td><input type="checkbox" data-id="2" data-tipe="delete"></td>
</tr>
<tr>
<td><input type="button" id="btnUpdate" value="Update"/>
</tr>
jQuery的
$(function(){
$('#btnUpdate').click(function(){
var cb = [];
$.each($('input[type=checkbox]:checked'), function(){
cb.push($(this).data('id') + ' -> ' +$(this).data('tipe'));
});
$('#status').val(cb.join("\n"));
})
});
http://stackoverflow.com/questions/42530480/how-do-i-pass-jquery-value-to-php/42531178#42531178 –
[用PHP jQuery的Ajax的POST示例](的可能的複製HTTP ://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php) –