如何使用jQuery检索所有选中复选框的名称?

Fri*_*ons 0 jquery

我想获取所有选中复选框的名称.我试过这个:

$("#movebutton").click(function()   {
    var selectedids = "";           
    alert($('.checkbos_gruppe[checked=checked]').attr("name"));             
});
Run Code Online (Sandbox Code Playgroud)

有没有人有更好的主意?

Nic*_*ver 5

你需要循环遍历它们,在这种情况下.map(),获取一组名称是一个很好的选择,例如:

$("#movebutton").click(function()   {
  var selectednames = $('.checkbos_gruppe:checked').map(function() { 
                      return this.name; 
                    }).get();
  alert(selectednames.join(", "));
});
Run Code Online (Sandbox Code Playgroud)

这将为您提供一系列name属性selectednames,然后根据需要使用它.确保.get()在最后使用,以便获得一系列名称.