2014-02-27 54 views
0

我对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(); 
      } 
     }); 
    }); 

的问题是,该插件的页面加载(我想这是因为触发(“鼠标松开”)),并初见成效下跌后活跃。

是否有任何触发器选择使其不活跃,或可能是另一个。 谢谢。

回答

0

通过为选定的书写订单插件解决问题。

+0

您能否提供一些代码片段,示例或链接? –