jquery获取checkbox的值并post提交
内容摘要
废话不多说,直接奉上代码:
http://code.jquery.com/jquery-1.7.2.min.js"></script>
</head>
<body>
<?php
$data = $_POST['data'];
$arr = json_decode($data);
v
http://code.jquery.com/jquery-1.7.2.min.js"></script>
</head>
<body>
<?php
$data = $_POST['data'];
$arr = json_decode($data);
v
文章正文
废话不多说,直接奉上代码:
http://code.jquery.com/jquery-1.7.2.min.js"></script>
</head>
<body>
<?php
$data = $_POST['data'];
$arr = json_decode($data);
var_dump($arr);
$a = array(1,2,3,4);
foreach($a as $v){
?>
<input type = "checkbox" class="checkbox" name="checkbox" value="<?=$v?>">
<?php
}
?>
<input type = "button" class="but_delet_choice" value="post">
</body>
<script>
$('.but_delet_choice').click(function(){
//获取全选之外的checkbox
var $check_boxes = $("input[name='checkbox']:checked");
if($check_boxes.length<=0){
alert('您未勾选,请勾选!');
return;
}
var array = new Array();
$check_boxes.each(function(){
var array_push = new Array();
array_push.push($(this).val());
array_push.push(2);
array.push(array_push);
})
$.post(
'test1.php',
{
data : JSON.stringify(array)
}
);
return false;
});
</script>
</html>
</head>
<body>
<?php
$data = $_POST['data'];
$arr = json_decode($data);
var_dump($arr);
$a = array(1,2,3,4);
foreach($a as $v){
?>
<input type = "checkbox" class="checkbox" name="checkbox" value="<?=$v?>">
<?php
}
?>
<input type = "button" class="but_delet_choice" value="post">
</body>
<script>
$('.but_delet_choice').click(function(){
//获取全选之外的checkbox
var $check_boxes = $("input[name='checkbox']:checked");
if($check_boxes.length<=0){
alert('您未勾选,请勾选!');
return;
}
var array = new Array();
$check_boxes.each(function(){
var array_push = new Array();
array_push.push($(this).val());
array_push.push(2);
array.push(array_push);
})
$.post(
'test1.php',
{
data : JSON.stringify(array)
}
);
return false;
});
</script>
</html>
复制代码 代码如下:
array(4) {
[0]=>
array(2) {
[0]=>
string(1) "1"
[1]=>
int(2)
}
[1]=>
array(2) {
[0]=>
string(1) "2"
[1]=>
int(2)
}
[2]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
int(2)
}
[3]=>
array(2) {
[0]=>
string(1) "4"
[1]=>
int(2)
}
}
这里仅仅是简单实现下,给大家一个参考,小伙伴们可以自由扩展。
代码注释