2013-10-17 15 views
0

返回對於每個返回的元素中的每個元素由對於由

{! followers } 

一個複選框被創建。我有一個提交按鈕,'提交'我想記錄哪些複選框是和不被檢查。

  <apex:repeat value="{! followers }" var="follower"> 
      $('#attendees').append(
       $('<div>').css('display','inline').append(
        $('<input>', {type:"checkbox"}).addClass('myCheckBox').attr('id', '{! follower.subscriberId }') 
       ).append(
        $('<label>').text('{! follower.Subscriber.Name }') 
       ) 
      ); 
     </apex:repeat> 

如何將這些複選框的值傳遞給提交按鈕?當他們到達提交按鈕時,我只想alert()或console.log()。

也許這樣的事情?

  if ($('.myCheckBox').is(':checked')){ 
       alert($('.myCheckBox').attr(???)) 
      }; 

或者這個?

  if ($('#attendees input').is(':checked')){ 
       alert($('#attendees input').attr('???')) 
      }; 

回答

2

您可以使用.map()函數獲取值的完整列表內部數組:

var cbValues = $(".myCheckBox").map(function() { 
    return this.checked; 
}).get(); 
+1

簡單。打我吧:) –

+0

乾杯,這個作品很棒。 – Daft