2014-02-27 99 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

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

相關問題