【发布时间】:2015-02-04 17:13:00
【问题描述】:
在我之前的问题中,我谈到了 bootstrap 选择插件,其中destroy 方法正在做一些我不想要的事情。我手动编辑插件,但这不是一个好习惯。
Bootstrap select destroy removes the original select from DOM
我想使用自定义方法扩展插件,以便它可以完全按照我的意愿行事。
我使用以下方法扩展插件:
$.extend(true, $.fn.selectpicker.prototype, {
customRemove: function () {
this.$newElement.remove();
this.$element.show();
}
});
这位于引导选择脚本文件下的另一个js文件中。
如何调用这个新方法?我尝试了以下但没有成功:
$('select#begin' + _week + _day).selectpicker("customRemove");
或
$('select#begin' + _week + _day).selectpicker().customRemove();
我错过了什么吗?
bootstrap select插件中destroy函数的原方法:
remove: function () {
this.$newElement.remove();
this.$element.show();
}
【问题讨论】:
-
selectpicker()是否返回this?如果不是,那么您不能链接该方法。 -
我在插件中看到
return this;所以是的 -
试试 selectpicker.prototype.customRemove();
-
@Dave 谢谢我现在可以调用我的方法,但变量未定义。如何获取位于
Selectpicker类中的this.$newElement和this.$element的值? -
检查.. customRemove: function (ele) { ele.$newElement.remove(); ele.$element.show(); }
标签: jquery twitter-bootstrap bootstrap-select