【问题标题】:jquery ui multiselect does not work with multiple + single selectjquery ui multiselect不适用于多选+单选
【发布时间】:2012-05-26 10:00:36
【问题描述】:

我正在使用这个插件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>

问题是多选有效,但单选根本不起作用(我无法选择任何内容,列表被下拉,但没有选择任何内容)。 知道为什么吗?非常感谢。

【问题讨论】:

  • 您在控制台中看到任何错误吗?能否请您发布#ceva 选择的HTML。
  • 我已经编辑了添加选择的问题
  • 解决了!在这个插件中,单选是单选按钮而不是复选框。我会立即发布答案,以防其他人面临这个问题:)

标签: javascript jquery select multi-select


【解决方案1】:
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>

【讨论】:

    猜你喜欢
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    相关资源
    最近更新 更多