2012-11-12 27 views
0

的價值我有jQuery的以下小提琴:遍歷複選框來檢索檢查者

var checks = $('input[name= "ScheduleCharge[hspecialty][]"]:checked'); 
$(checks).each(function(){ 
    alert($(this).value()); 
}); 

這只是刷新頁面。如果我將$(this).value()替換爲1,則會根據複選框的數量提醒1正確的次數。有什麼建議麼 ?

回答

3

您需要使用val()而不是value(),因爲value()未由jquery定義,並且錯誤會導致頁面刷新。

var checks = $('input[name= "ScheduleCharge[hspecialty][]"]:checked'); 
$(checks).each(function(){ 
    alert($(this).val()) ; 
}) ; 
0

這裏$(this)jQuery對象和值是無效的屬性,這

使用.val()代替

alert($(this).val()) ; $(this) jQuery Object 

如果你想使用值屬性使用DOM對象

alert(this.value) ; this DOM Object