2009-07-13 26 views
0

我有一个多选框,当我点击链接“共享”时出现。现在我想要获取所选选项的值。我怎么做?它是$('#userList')。val()? 而且我也怀疑我是否可以像这样编写选项的value属性:?如何获取选择框的多个值?

$(document).ready(function(){ 
    var flag=0; 
    $('#share_form').hide(); 

      $('.Share').click(function(){ 
     if(flag==1){ 
      $('#share_form').hide('fast'); 
      flag=0; 
     } 
     else{ 
      $('#share_form').show('slow'); 
     flag=1; 
      return false; 
     } 

    }); 

     });//ready 

    <a href="#" class="Share">Share</a> 
    <div id="share_form"> 
    <p>Select the users with whom you want to share the Form</p> 

    <select id="userList" name="userList" multiple> 
     <?php foreach($users as $user){ ?> 
      <option value="$user['User']['name']"><?php echo $user['User']['name'];?></option> 
     <?php }?> 
    </select> 
    </div> 

回答

3

选择器/ selected

$("#userList option:selected").each(function(){ 
    alert($(this).text()); 
});