2010-12-11 40 views

回答

5

你通過他們需要循環,在這種情況下.map()是一個偉大的選擇,以獲得名稱的數組,例如:

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

這將讓你的selectednames中的name屬性的數組,然後根據需要使用它。請務必在末尾使用.get(),以便您獲得只需一組名稱。

+0

thx !!!工作正常 – 2010-12-11 11:08:46

1

使用:

var names = $('.checkbos_gruppe:checked').map(function(index, elem) { 
    return this.name; 
}).get(); 
+0

'names'將是一個jQuery對象;) – 2010-12-11 11:07:42

+0

yay,如果您經常使用'.map()'方法,則會發生:p fixed;) – jAndy 2010-12-11 11:13:04

相關問題