如何从相扑选择下拉列表中获取下拉ID?

时间:2015-12-28 14:02:20

标签: javascript php jquery

我无法从相扑选择下拉列表中获取下拉列表ID。下拉列表ID正在动态更改。页面上有多个下拉列表。显示示例代码。

 <div id="shareOnFriendsList" > 
        <select id="friendsList_<?php echo $postID;?>" class="testSelAll" multiple="multiple" placeholder="Share On Your Friends" title="Select & Share Your Friends" >
            <?php 
            $sql_getFriends = "SELECT id, CONCAT(firstname,' ',lastname) AS username FROM register WHERE id IN($friend_id[0])";
            $getFriends_row = mysqli_query($con, $sql_getFriends);
            while($row =  mysqli_fetch_assoc($getFriends_row))
            {
            ?><option value="<?php echo $row['id'];?>" > <?php echo $row['username'];?> </option><?php
            }?>                   
       </select>       
    </div>

在我的javascript中,我有:

<script type="text/javascript">
    $(document).ready(function () {         
    window.testSelAll = $('.testSelAll').SumoSelect({okCancelInMulti:true, selectAll:true });               
        $('.btnOk').on('click', function() {                                
            var obj = [],
            selectedFriendsList = '';
            $('.testSelAll option:selected').each(function(i) {
                obj.push($(this).val());
                $('.testSelAll')[0].sumo.unSelectItem(i);
            });
            for(var i=0;i<obj.length;i++) 
            {selectedFriendsList += ',' + obj[i]};              
            alert('.testSelAll select').attr('id'); //get select id..       
        });
    }); 
</script>

1 个答案:

答案 0 :(得分:1)

你有错误的选择器来定位选择元素。它应该是:

$('select.testSelAll').attr('id')