在我之前的问题中,我谈论的是 Bootstrap 选择插件,其中 destroy 方法正在执行我不想要的操作。我手动编辑插件,但这不是一个好的做法。
Bootstrap select destroy removes the original select from DOM
我想使用自定义方法扩展该插件,以便它可以完全执行我想要的操作。
我用以下方法扩展插件:
$.extend(true, $.fn.selectpicker.prototype, {
customRemove: function () {
this.$newElement.remove();
this.$element.show();
}
});
它位于 Bootstrap 选择脚本文件下的另一个 js 文件中。
如何调用这个新方法?我尝试了以下方法但没有成功:
$('select#begin' + _week + _day).selectpicker("customRemove");
或
$('select#begin' + _week + _day).selectpicker().customRemove();
我错过了什么吗?
bootstrap select插件中destroy函数的原始方法:
remove: function () {
this.$newElement.remove();
this.$element.show();
}
最佳答案
我认为,您在其他问题中的答案是正确的:
https://stackoverflow.com/a/31852632/4928642
jQuery.fn.selectpicker.Constructor.prototype.customRemove = function () {
this.$newElement.remove();
this.$element.show();
};
然后
$smth.selectpicker("customRemove");
关于jquery - 扩展 Bootstrap 选择插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27334426/