select2 > 如何更改原型函数“MultipleSelection.prototype.selectionContainer”

问题描述 投票:0回答:1

我使用基于 jQuery 的库 Select2。

在库中https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.js定义了以下函数:

  MultipleSelection.prototype.selectionContainer = function () {
    var $container = $(
      '<li class="select2-selection__choice">' +
        '<button type="button" class="select2-selection__choice__remove" ' +
        'tabindex="-1">' +
          '<span aria-hidden="true">&times;</span>' +
        '</button>' +
        '<span class="select2-selection__choice__display"></span>' +
      '</li>'
    );

    return $container;
  };

如何在不更改原始文件的情况下更改/覆盖此功能?

javascript jquery-select2
1个回答
0
投票
  window.Select2['class'].multi.prototype.selectionContainer = function () {
    var $container = $(
      '<li class="select2-selection__choice">' +
        '<button type="button" class="select2-selection__choice__remove" ' +
        'tabindex="-1">' +
          '<span aria-hidden="true">&times;</span>' +
        '</button>' +
        '<span class="select2-selection__choice__display"></span>' +
      '</li>'
    );

    return $container;
  };

你可以在那里改变任何东西......

© www.soinside.com 2019 - 2024. All rights reserved.