简体   繁体   中英

multiple select checkbox in jquery

I want to show the multiple value of checkbox in a div or textbox.

function countChecked() {
    var n = $("input:checked").val();
    $("div").text(n + (n === 1 ? " is" : " are") + " checked!");
}
countChecked();
$(":checkbox").click(countChecked);

try this:

function countChecked() {
  var n = 0;
  $(":checkbox:checked").each(function(){
     n += parseInt(this.value, 10)
  })
  $("div").text(n + (n === 1 ? " is" : " are") + " checked!");
}
function countChecked() {
    var n= "";
    $("input[type=checkbox]:checked").each(function(){
        n += $(this).val() + " ";
    });
    $("#change").text(n);
}
countChecked();
$(":checkbox").click(countChecked);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM