我使用基于 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">×</span>' +
'</button>' +
'<span class="select2-selection__choice__display"></span>' +
'</li>'
);
return $container;
};
如何在不更改原始文件的情况下更改/覆盖此功能?
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">×</span>' +
'</button>' +
'<span class="select2-selection__choice__display"></span>' +
'</li>'
);
return $container;
};
你可以在那里改变任何东西......