Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在多选下拉列表jquery中显示所有类别_Javascript_Jquery_Twitter Bootstrap_Angular Ui Bootstrap_Multi Select - Fatal编程技术网

Javascript 在多选下拉列表jquery中显示所有类别

Javascript 在多选下拉列表jquery中显示所有类别,javascript,jquery,twitter-bootstrap,angular-ui-bootstrap,multi-select,Javascript,Jquery,Twitter Bootstrap,Angular Ui Bootstrap,Multi Select,这是我的多选下拉列表代码 <select class="form-control" id="lstFruits" required multiple="multiple" name="catId[]"> @foreach($catlists as $category) <option value="{!! $category->id !!}" >{!! $category->name !!}</option> @end

这是我的多选下拉列表代码

<select class="form-control" id="lstFruits" required multiple="multiple" name="catId[]">
    @foreach($catlists as $category)
    <option value="{!! $category->id !!}"    >{!! $category->name !!}</option>
    @endforeach
</select>
<script type="text/javascript">
    $(function () {
        $('#lstFruits').multiselect({
            includeSelectAllOption: true
        });
        $('#btnSelected').click(function () {
            var selected = $("#lstFruits option:selected");
            var message = "";
            selected.each(function () {
                message += $(this).text() + " " + $(this).val() + "\n";
            });
            alert(message);
        });
    });
</script>

@foreach($catlist作为$category)
{!!$category->name!!}
@endforeach
$(函数(){
$('#lstFruits')。多选({
includeSelectAllOption:true
});
$(“#b选择”)。单击(函数(){
所选风险值=$(“#选择项:所选”);
var message=“”;
已选定。每个(函数(){
message+=$(this.text()++$(this.val()++“\n”;
});
警报(信息);
});
});
问题:

当我选择4个以上的类别时,它会显示4个选定类别,但我想在下拉列表中显示这4个类别

它显示以下内容:

我想要这样的东西,所有类别都应该显示出来

根据,您必须覆盖
按钮文本
属性:

$('#lstFruits').multiselect({
    ...
    buttonText: function(options, select) {
        var labels = [];
        options.each(function() {
            if ($(this).attr('label') !== undefined) {
                labels.push($(this).attr('label'));
            }else {
                labels.push($(this).html());
            }
        });
        return labels.join(', ') + '';
    }
});