如何获得使用jQuery所有选中的复选框的值 [英] How to get the values of all checked checkboxes using jQuery
本文介绍了如何获得使用jQuery所有选中的复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何通过复选框的选择的值。任何帮助或建议将是对我来说是很大的帮助。
由于现在这里是我的code我被困在通过复选框的值
的index.php
<表>
< PHP
的foreach($响应为$项){
回声'< TR>< TD><输入类型=复选框值=,$项目['身份证'。'>< / TD>< TD> 。 $项目['名称']。 '< / TD>< / TR>';
}
?>
< /表>
<按钮式=按钮级=btnadd> AddSelected< /按钮>
<脚本类型=文/ JavaScript的>
$(函数(){
$('。btnadd)。点击(函数(){
$阿贾克斯({
网址:process.php,
类型:'后',
数据:{} //我应该把这里通过检查复选框的值
成功:功能(数据){}
});
});
});
< / SCRIPT>
process.php
< PHP
$ array_ids = $ _ POST ['IDS']; //这将检索的ID
?>
解决方案
试试这个。
HTML code
<脚本类型=文/ JavaScript的SRC =JS / jquery.js和>< / SCRIPT>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$('。btnadd)。点击(函数(){
VAR校验值= $('输入[名称=的CheckBoxList]:检查)图(函数()。
{
返回$(这).VAL();
})。得到();
$阿贾克斯({
网址:loadmore.php,
类型:'后',
数据:{IDS:校验值},
成功:功能(数据){
}
});
});
});
< / SCRIPT>
<输入类型=复选框名称=的CheckBoxList值=1检查=检查/>
<输入类型=复选框名称=的CheckBoxList值=2检查=检查/>
<输入类型=复选框名称=的CheckBoxList值=4/>
<输入类型=复选框名称=的CheckBoxList值=5检查=检查/>
<输入类型=复选框名称=的CheckBoxList值=6/>
loadmore.php code
< PHP
的print_r($ _ POST ['IDS']);
?>
输出在loadmore.php
阵列
(
[0] => 1
[1] => 2
[2] => 5
)
就是这样。
干杯。
I don't know how to pass the selected values of the checkboxes. Any help or suggestions will be a big help for me.
As of now here is my code I am stuck in passing the values of the checkboxes
index.php
<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
?>
解决方案
Try This.
HTML CODE
<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 CODE
<?php
print_r($_POST['ids']);
?>
OUTPUT IN loadmore.php
Array
(
[0] => 1
[1] => 2
[2] => 5
)
That's IT.
Cheers.
这篇关于如何获得使用jQuery所有选中的复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文