Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 选择多选顺序。页面加载时插件处于活动状态_Javascript_Jquery_Multi Select_Jquery Chosen - Fatal编程技术网

Javascript 选择多选顺序。页面加载时插件处于活动状态

Javascript 选择多选顺序。页面加载时插件处于活动状态,javascript,jquery,multi-select,jquery-chosen,Javascript,Jquery,Multi Select,Jquery Chosen,我不太熟悉jquery,所以不要太严格。任务是在选定的multiselect插件中进行排序。 以下是解决方法: $(function(){ $("select#Books_id_author").each(function(){ if($(this).data("order")==true){ $(this).val(''); $(this).chosen();

我不太熟悉jquery,所以不要太严格。任务是在选定的multiselect插件中进行排序。 以下是解决方法:

$(function(){
        $("select#Books_id_author").each(function(){
            if($(this).data("order")==true){
                $(this).val('');
                $(this).chosen();
                var $ordered = $('[name="_'+jQuery(this).attr('id')+'"]');
                var selected = $ordered.val().split(',');
                var chosen_object = $(this).data('chosen');
                $.each(selected, function(index, item){
                    $.each(chosen_object.results_data, function(i, data){
                        if(data.value == item){
                            $("#"+data.dom_id).trigger('mouseup');
                        }
                    });
                });
                $(this).data("backupVal",$(this).val());
                $(this).change(function(){
                    var backup = $(this).data("backupVal");
                    var current = $(this).val();
                    if(backup == null){
                        backup = [];
                    }
                    if(current == null){
                        current = [];
                    }
                    if(backup.length > current.length){
                        $.each(backup, function(index, item) {
                            if($.inArray(item, current) < 0){
                                for(var i=0; i<selected.length; i++){
                                    if(selected[i] == item){
                                        selected.splice(i,1);
                                    }
                                }
                            }
                        });
                    }else if(backup.length < current.length){
                        $.each(current, function(index, item) {
                            if($.inArray(item, backup) < 0){
                                selected.push(item);
                            }
                        });
                    }
                    $ordered.val(selected.join(','));
                    $(this).data("backupVal",current);
                });
            }else{
                $(this).chosen();
            }
        });
    });
$(函数(){
$(“选择书籍id作者”)。每个(函数(){
if($(this).data(“订单”)==true){
$(this.val(“”);
$(this.selected();
var$ordered=$('[name=“'+jQuery(this.attr('id')+'”]);
所选变量=$ordered.val().split(',');
var selected_object=$(this).data('selected');
$。每个(已选择,功能(索引,项目){
$.each(所选对象.结果\数据,函数(i,数据){
如果(data.value==项目){
$(“#”+data.dom_id.trigger('mouseup');
}
});
});
$(this.data(“backupVal”,“this.val());
$(this).change(function(){
var backup=$(this).data(“backupVal”);
var current=$(this.val();
如果(备份==null){
备份=[];
}
如果(当前==null){
电流=[];
}
如果(backup.length>current.length){
$。每个(备份、功能(索引、项目){
如果($.inArray(项目,当前)<0){

对于(var i=0;i问题,通过为所选对象编写订单插件解决。

您能提供一些代码片段、示例或链接吗?