当我点击“分享”链接时,会出现一个多选框。现在我想获取所选选项的值。我怎么做?是$('#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>
答案 0 :(得分:3)
选择器/ selected
$("#userList option:selected").each(function(){
alert($(this).text());
});