jQuery UI widget缺少选项方法

时间:2014-05-06 21:54:45

标签: javascript jquery jquery-ui jquery-ui-widget-factory

我有点困惑为什么这个新创建的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/

谢谢!

1 个答案:

答案 0 :(得分:0)

解决方案:文档中不是很清楚,但使用以下选项设置选项:

$('.test').oTest('option', {'string': 'meow'});

http://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/