【问题标题】:Is it possible to disable chosen.js for a specific select box?是否可以为特定的选择框禁用 selected.js?
【发布时间】:2013-02-08 17:41:20
【问题描述】:

鉴于某个事件(例如,单击按钮),我想为特定选择框禁用 Chosen.js。

这可能吗?

【问题讨论】:

    标签: html-select jquery-chosen


    【解决方案1】:

    虽然不需要单击按钮,但我也有类似的要求,我只是想为特定选择框启用/禁用选择。

    我的解决方案是为每个您不想使用 Chosen 的 select 元素添加 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));
            }
          });
        }
      });
    

    【讨论】:

      【解决方案2】:

      例如,您有一个带有 no-chosen 类的选择,您可以这样做:

      $("select:not('.no-chosen')").chosen();
      

      这意味着它需要所有选择,除了没有选择的类。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-02
        • 1970-01-01
        • 1970-01-01
        • 2012-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多