好的,整理好了。下载未缩小的 JS (4.0.6-rc.0) 并执行以下操作:
为了去掉“十字架”,改变了这个
MultipleSelection.prototype.selectionContainer = function () {
var $container = $(
'<li class="select2-selection__choice">' +
'<span class="select2-selection__choice__remove" role="presentation">' +
'×' +
'</span>' +
'</li>'
);
return $container;
};
到这里
MultipleSelection.prototype.selectionContainer = function () {
var $container = $(
'<li class="select2-selection__choice"></li>'
);
return $container;
};
要添加“取消选择标签点击”,添加此点击
this.$selection.on(
'click',
'.select2-selection__choice',
function (evt) {
// Ignore the event if it is disabled
if (self.options.get('disabled')) {
return;
}
var data = Utils.GetData(this, 'data');
self.trigger('unselect', {originalEvent: evt, data: data})
evt.stopPropagation()
}
)
函数内部
MultipleSelection.prototype.bind = function (container, $container) {
...
}
(非常类似于其中用于正常处理“交叉”点击的现有代码)
最后,将相关的 css 从 cursor: default 调整为 cursor: pointer
最终结果: