0
執行公共方法與訪問外部文件中定義的功能的問題,請給一個忠告,我該如何解決以下。我如何我可以從JavaScript對象
頁代碼:
var be = null;
$(document)
.ready(function() {
be = $("#article-content")
.bootstrapeditor({
//
});
// how can I call public method wizardWorkedOut from
// https://jsfiddle.net/f0rza/572q21fj/ ?
});
https://jsfiddle.net/f0rza/jhotm90r/
外部腳本:
! function($) {
var BootstrapEditor = function(element, options) {
this.canDemolishEditor = true;
};
BootstrapEditor.prototype.wizardWorkedOut = function() {
this.wizardWorkedOut();
};
BootstrapEditor.prototype = {
constructor: BootstrapEditor,
wizardWorkedOut: function() {
console.log('bootstrap-editor instance: wizardWorkedOut');
this.canDemolishEditor = true;
}
};
$.fn.bootstrapeditor = function(option, val) {
return this.each(function() {
var $this = $(this),
data = $this.data("bootstrapeditor"),
options = typeof option === "object" && option;
if (!data) {
$this.data("bootstrapeditor",
(data = new BootstrapEditor(this, $.extend({},
$.fn.bootstrapeditor.defaults, options))));
}
if (typeof option === "string") data[option](val);
});
};
$.fn.bootstrapeditor.defaults = {
onRender: function(date) {
return "";
}
};
$.fn.bootstrapeditor.Constructor = BootstrapEditor;
}(window.jQuery);
https://jsfiddle.net/f0rza/572q21fj/
您必須創建'BootstrapEditor'實例,然後才能調用它的方法,例如'wizardWorkedOut' – hindmost
對象初始化即使我得到一個錯誤:http://take.ms/re9FU – f0rza