本文介紹了如何使用jQuery獲取所有選中復(fù)選框的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我不知道如何傳遞復(fù)選框的選定值.任何幫助或建議都會對我有很大幫助.
I don't know how to pass the selected values of the checkboxes. Any help or suggestions will be a big help for me.
到目前為止,這是我的代碼,我一直在傳遞復(fù)選框的值
As of now here is my code I am stuck in passing the values of the checkboxes
<table>
<?php
foreach($response as $item){
echo '<tr><td><input type="checkbox" value="' .$item['id']. '"></td><td>' . $item['name'] . '</td></tr>';
}
?>
</table>
<button type="button" class="btnadd">AddSelected</button>
<script type="text/javascript">
$(function() {
$('.btnadd').click(function() {
$.ajax({
url: 'process.php',
type: 'post',
data: { }, // what should I put here to pass the value of checked checkboxes
success: function(data) {}
});
});
});
</script>
process.php
<?php
$array_ids = $_POST['ids']; // this will retrieve the id's
?>
推薦答案
試試這個.
HTML 代碼
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.btnadd').click(function(){
var checkValues = $('input[name=checkboxlist]:checked').map(function()
{
return $(this).val();
}).get();
$.ajax({
url: 'loadmore.php',
type: 'post',
data: { ids: checkValues },
success:function(data){
}
});
});
});
</script>
<input type="checkbox" name="checkboxlist" value="1" checked="checked" />
<input type="checkbox" name="checkboxlist" value="2" checked="checked" />
<input type="checkbox" name="checkboxlist" value="4" />
<input type="checkbox" name="checkboxlist" value="5" checked="checked" />
<input type="checkbox" name="checkboxlist" value="6" />?
loadmore.php 代碼
<?php
print_r($_POST['ids']);
?>
在 loadmore.php 中輸出
Array
(
[0] => 1
[1] => 2
[2] => 5
)
就是這樣.
干杯.
這篇關(guān)于如何使用jQuery獲取所有選中復(fù)選框的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!