我有点困惑为什么这个新创建的jQuery UI Widget没有选项方法?
(function ($) {
$.widget('ui.oTest', {
options: {},
_create: function(){
$('<span>',{
html: 'oTest Span'
}).appendTo(this.element);
}
});
})(jQuery);
$('.test').oTest();
$('.test').option(); //Uncaught TypeError: Object [object Object] has no method 'option'
这里是小提琴:http://jsfiddle.net/fwWc8/
谢谢!
答案 0 :(得分:0)
解决方案:文档中不是很清楚,但使用以下选项设置选项:
$('.test').oTest('option', {'string': 'meow'});
http://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/