Object [object Object]没有方法'discussionwidget'

时间:2013-09-23 08:17:52

标签: javascript jquery html

我是JQuery&的初学者HTML。我正在创建一个名为讨论向导的小部件。在运行时,我收到以下错误:对象[object Object]没有方法'discussionwidget'

不确定,可能是同样的原因: 请帮忙:

小部件代码:

(function ($, undefined) {
    $.widget('ui.discussionwidget', {
        options: {
            userName : 'Arti Agarwal',
            title:"",
            width:"",
            containerClass:".ui-content-gutter"
        },

        _create: function () {
            //Create the structure of Discussion Widget
            var widgetStructure = '<div class="ui-discussion hGridPx_120 wGridPx_10"><div  class="ui-discussion-header hGridPx_18 wGridPx_10"></div><div class="ui-discussion-container hGridPx_100 wGridPx_75"><div class="ui-discussion-messages hGridPx_75 wGridPx_74"> <ul id="ui-discussion"></ul></div> <div class="ui-discussion-input hGridPx_10 wGridPx_10"><label class="input hGridPx_10 wGridPx_60"><span>Add or reply to a comment...</span><textarea id="message" class="hGridPx_10 wGridPx_60"></textarea></label><div class="ui-discussion-send hGridPx_10 wGridPx_10"><a href="#" id="addchat"><span class="ui-image-addchat">Add</span></a> <a href="#" id="replychat" class="ui-reply-disabled"><span class="ui-image-replychat">Reply</span></a></div></div></div></div>';
            widgetStructure.appendTo($($(this.options.containerClass));
        },
widget: function () {
            return this.element;
        },

    });

    var CloseDiscussionWidget = function() {

    }

})(jQuery);

我是从一个页面调用它:

<script>
        (function ($) {

            //Load discussion history fist time
            $(document).ready(function () {
                GetCurrentUserDetails('arti.agarwa');
                Discussionwidget = $('.ui-content-gutter').discussionwidget({ containerClass: ".ui-content-gutter" });
        } (jQuery));
    </script>

1 个答案:

答案 0 :(得分:0)

代码中的语法错误很少,请尝试

(function ($, undefined) {
    $.widget('ui.discussionwidget', {
        options: {
            userName: 'Arti Agarwal',
            title: "",
            width: "",
            containerClass: ".ui-content-gutter"
        },

        _create: function () {
            // Create the structure of Discussion Widget
            var widgetStructure = $('<div class="ui-discussion hGridPx_120 wGridPx_10"><div  class="ui-discussion-header hGridPx_18 wGridPx_10"></div><div class="ui-discussion-container hGridPx_100 wGridPx_75"><div class="ui-discussion-messages hGridPx_75 wGridPx_74"> <ul id="ui-discussion"></ul></div> <div class="ui-discussion-input hGridPx_10 wGridPx_10"><label class="input hGridPx_10 wGridPx_60"><span>Add or reply to a comment...</span><textarea id="message" class="hGridPx_10 wGridPx_60"></textarea></label><div class="ui-discussion-send hGridPx_10 wGridPx_10"><a href="#" id="addchat"><span class="ui-image-addchat">Add</span></a> <a href="#" id="replychat" class="ui-reply-disabled"><span class="ui-image-replychat">Reply</span></a></div></div></div></div>');

            //Missing ) here
            widgetStructure.appendTo($($(this.options.containerClass)));
        },
        widget: function () {
            return this.element;
        },

        destroy: function () {
            $.Widget.prototype.destroy.call(this);
        }//extra , here

    });

    var CloseDiscussionWidget = function () {

    }

})(jQuery);

//missing }) here
(function ($) {
    // Load discussion history fist time
    $(document).ready(function () {
        //GetCurrentUserDetails('arti.agarwa');
        Discussionwidget = $('.ui-content-gutter').discussionwidget({
            containerClass: ".ui-content-gutter"
        });
    })
}(jQuery));

dom ready块也可以写成如下 - 不需要使用包装函数

// Load discussion history fist time
jQuery(function ($) {
    GetCurrentUserDetails('arti.agarwa');
    Discussionwidget = $('.ui-content-gutter').discussionwidget({
        containerClass: ".ui-content-gutter"
    });
})