繁体   English   中英

TypeError:this.functionName不是函数

[英]TypeError: this.functionName is not a function

所以我创建了一个小的javascript类,应该是AJAX在PHP文件中发布的东西。 该课程如下:

var cms = cms || {};

cms.load_view = (function() {
    return {
        change: function() {
            jQuery("#layout-switch a").on('click', function()
                {
                    jQuery('#layout-switch a').removeClass('current');
                    jQuery(this).addClass('current');
                    var column_number = jQuery(this).attr('data-name');
                    var category = jQuery("#cat_id").val();
                    var data = {mode: column_number, cid: category};
                    this.postChange(data);
                });
        },
        postChange: function(data) {
                jQuery.ajax({
                    type: 'post',
                    url: SITEURL + "/modules/digishop/loadcategory.php",
                    data: data,
                    beforeSend: function () {
                        jQuery('#digishop').animate({
                            opacity: 0
                        }, 250, function () {
                            jQuery(this).addClass(column_number);
                            jQuery(this).animate({
                                opacity: 1
                            }, 250);
                        });
                    },
                    success: function (html) {
                        jQuery("#digishop").html(html);
                    }
                });
            return true;
        }
    }
})(jQuery);
jQuery(document).ready(function() {
    cms.load_view.change();
});

但是,当我单击选择器时,Firebug说postChange在第一种方法中调用时不是函数,即this.postChange(data);

有任何想法吗?

谢谢!

在更改功能中, this是对您单击的链接的引用。 替换this.postChange(data); with cms.load_view.postChange(data);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM