jquery ui multiselect不适用于多个+单选

时间:2012-05-26 10:00:36

标签: javascript jquery select multi-select

我正在使用此插件http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/#single进行多选,并且在同一页面中也希望单个选择。 基本上我有2个选择 - 一个是多个,另一个是单一,但我想要两个相同的样式。 所以我试试:

<script type="text/javascript">
        $(function(){
        $("#altceva").multiselect({
            multiple: false,
            header: "Select an option",
            noneSelectedText: "Select an Option",
            selectedList: 1
        });

         $("#ceva").multiselect();
    });     
    </script>

和选择:

<select name="123_cat[]" id = "ceva" multiple="multiple" size="5">  
   <?php foreach($subcategories['categories'] as $sc) { ?>
   <optgroup label="<?php echo $sc['name']; ?>">
    <?php foreach ($sc['subcategories'] as $ss){?>                              
             <option id = "123_cat" value="<?php echo $ss['sid']; ?>" <?php if (isset($_GET['123_cat'])) { if(in_array($ss['sid'], $_GET['123_cat'])) echo "selected = 'selected'";} else { if(in_array($ss['sid'], $the_subcategories)) echo "selected = 'selected'"; } ?>><?php echo $ss['name']; ?></option>
        <?php }?>

                   

    <label for="oras">Oras</label>  
       <select name="123_city" id = "altceva">      
          <?php foreach($ac as $rc) {?> 
             <option id = "123_city" value="<?php echo $rc['slug']; ?>" <?php if         (isset($_GET['123_city'])) { if ($rc['slug'] == $_GET['123_city']) echo 'selected =   "selected"';} else { if ($rc['slug'] == $my_data->city) echo 'selected = "selected"';} ?>>           <?php echo $rc['name']; ?> </option>
        <?php } ?>

            </select>
问题是多选是有效的,但是单选不起作用(我不能选择任何东西,列表会被删除,但没有被选中)。 任何想法为什么?非常感谢。

1 个答案:

答案 0 :(得分:0)

altceva should be the id of multiselect dropdown and ceva should be the id of single dropdown.... Go for the below code...:)

<script type="text/javascript">
        $(window).load(function(){ 
        $("#altceva").multiselect({
            multiple: true,
            header: false,
            noneSelectedText: "Select an Option",
            selectedList: 1
        });

         $("#ceva").multiselect({
            multiple: false,
            header: false,
            noneSelectedText: "Select an Option",
            selectedList: 1
        });
    });     
    </script>