我想在这里选中的复选框的值,但它是不确定的,因为它成为一个数组。请帮我该怎么办呢..谢谢..
<形式GT;
<输入类型=复选框值=名称=函[]/>
<输入类型=复选框值=BNAME =函[]/>
<输入类型=复选框值=CNAME =函[]/>
<输入类型=按钮值=提交的onclick =拉尼()/>
< /形式GT;
<脚本>
功能拉尼(){
$阿贾克斯({
类型:后,
网址:ajax.php
数据:{
妲:$([名称=号])VAL()。
},
成功:函数(MSG){
警报(味精);
}
})
}
< / SCRIPT>
解决方案
在这里,你会得到一个变量选中的复选框值 checkbox_value
后来被 |
$(#BTN _)。在('点击',函数(){
VAR checkbox_value =;
$(:复选框)每个(函数(){。
VAR器isChecked = $(本)。是(:选中);
如果(器isChecked){
checkbox_value + = $(本).VAL()+|;
}
});
警报(checkbox_value);
//你真棒code调用AJAX
});
样品展示
学习jQuery:简单和容易的jQuery教程博客
I want to get the values of the checked checkbox here but it is undefined because it becomes an array.. Please help me how to do it.. thank you..
<form>
<input type="checkbox" value="a" name="letter[]" />
<input type="checkbox" value="b" name="letter[]" />
<input type="checkbox" value="c" name="letter[]" />
<input type="button" value="submit" onclick="rani()" />
</form>
<script>
function rani(){
$.ajax({
type:"post",
url:"ajax.php",
data:{
radha:$("[name=letter]").val(),
},
success:function(msg){
alert(msg);
}
})
}
</script>
解决方案
Here you will get selected checkbox values in a variable checkbox_value
and later split by |
.
$("#btn_").on('click', function () {
var checkbox_value = "";
$(":checkbox").each(function () {
var ischecked = $(this).is(":checked");
if (ischecked) {
checkbox_value += $(this).val() + "|";
}
});
alert(checkbox_value);
// your awesome code calling ajax
});
Sample Demo
Learn jQuery: Simple and easy jQuery tutorials blog