我有一个网页,其中有一个检查按钮,如果选择了一个按钮,然后它会显示一个警报,如果有两个,那么它应该显示两个警报,但它只显示一个首先选择的按钮。
我正在使用以下代码
$(document).ready(function(){
$("#email_multiple").click(function(){
var n = $("input:checked").length;
//alert(n);
//for(var i=1;i<=$("input:checked").length;i++){alert(n);}
if(!($("input:checked").length)){
alert('Please make a check on check box field thanks hahahahha...');
return false;
}
if(n==1){
var bb = $("input:checked").val();
alert(bb);
presenter.command("emailSend",{
"toEmail": "",
"toName": "",
"subject": "",
"body": "Single Attachment",
"bodyHtml":"",
"attachments": ["/images/Animal/pdf/"+bb+".pdf"]
});
$('input[type=checkbox]').attr('checked',false);
}
if(n==2){
var bb = $("input:checked").val();
alert(bb);
presenter.command("emailSend",{
"toEmail": "",
"toName": "",
"subject": "",
"body": "Single Attachment",
"bodyHtml":"",
"attachments": ["/images/Animal/pdf/"+bb+".pdf","/images/Animal/pdf/"+bb+".pdf"]
});
$('input[type=checkbox]').attr('checked',false);
}
});
});
答案 0 :(得分:1)
$(document).ready(function(){
$("#email_multiple").click(function(){
var n = $("input:checked").length;
if(!($("input:checked").length)){
alert('Please make a check on check box field thanks hahahahha...');
return false;
}
for(var i=0; i < n; i++){
var bb = $($("input:checked")[i]).val();
alert(bb);
}
});
});