2013-02-08 141 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)); 
     } 
     }); 
    } 
    }); 
相关问题