好了,想着這對於多一點的時間後,我意識到,插件功能的默認功能是它返回JQuery的鏈條問題(道歉,下面通過一些打字稿):
我原本有:
function Plugin(option, args) {
return this.each(function() {
var $this = $(this);
var data = $this.data('xyz.wizard');
var options = $.extend(option, Wizard.DEFAULTS) as WizardOptions;
if (!data) {
data = new Wizard(this, options);
$this.data('xyz.wizard', data);
}
if (typeof option === 'string') return data[option](args);
});
}
,然後在頂部增加了一個新的部分:
function Plugin(option, args) {
// New Part - If option is a string, then call the named method and return the result
if (typeof option === 'string') {
var data = $(this).data('xyz.wizard');
if(data) {
return data[option](args);
}
}
// Otherwise do the default
return this.each(function() {
var $this = $(this);
var data = $this.data('xyz.wizard');
var options = $.extend(option, Wizard.DEFAULTS) as WizardOptions;
if (!data) {
data = new Wizard(this, options);
$this.data('xyz.wizard', data);
}
// if (typeof option === 'string') return data[option](args);
});
}
它似乎工作,但我不知道這是否是CORRE ct方法。
給出一些詳細的代碼是當前頁面變量和getactivepage定義 –