如何获得选择框的多个值? [英] how to get the multiple values of a select box?

查看:61
本文介绍了如何获得选择框的多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多重选择框,当我单击链接共享"时会出现.现在,我想获取所选选项的值.我怎么做?是$('#userList').val()吗? 而且我也怀疑我是否可以这样写option的value属性:?

I have a multiple select box which appears when I click the link 'Share'. Now I want to get the values of the options selected. How do I do that? is it $('#userList').val()? And also I have a doubt whether I could wrote the value property of option like this: ?

   $(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>

推荐答案

选择器/已选择

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

这篇关于如何获得选择框的多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆