2013-02-08 140 views

回答

1

我有類似的要求,雖然它不需要按鈕點擊,我只是想啓用/禁用選擇特定的選擇框。

我的解決方案是每個你不想使用的select元素使用Chosen,添加CSS類'no-chzn'。然後在chosen.jquery.js中,將以下幾行添加到構造函數中(該值接近line 533 in version 1.1.0):

$.fn.extend({ 
    chosen: function(options) { 
     if (!AbstractChosen.browser_is_supported()) { 
     return this; 
     } 
     return this.each(function(input_field) { 
     var $this, chosen; 
     $this = $(this); 
     if ($this.parent().hasClass("chosen-disable")) { return; } // Just add this line! 
     chosen = $this.data('chosen'); 
     if (options === 'destroy' && chosen) { 
      chosen.destroy(); 
     } else if (!chosen) { 
      $this.data('chosen', new Chosen(this, options)); 
     } 
     }); 
    } 
    }); 
相關問題