首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript未捕获类型错误仅适用于Live环境,适用于Dev

问Javascript未捕获类型错误仅适用于Live环境,适用于Dev
EN

Stack Overflow用户
提问于 2014-12-11 23:57:55
回答 1查看 56关注 0票数 0

我有一个令人费解的问题。一小段javascript,用于在Wordpress子主题中设置一个给定的数字,并从父主题改编而来。该脚本在我的开发环境中工作得很好,但在使用完全相同的代码库的实时环境中,代码会失败并返回熟悉的

代码语言:javascript
复制
Uncaught TypeError: undefined is not a function

它似乎在第一次运行时运行良好,但在随后的运行中失败。在实时服务器上失败的特定代码行如下:

代码语言:javascript
复制
$(this).waypoint(function(direction) {

我已经反复检查了代码库(它是相同的),并检查了所有文件的权限(都是可读的)。我完全被弄糊涂了--有人能解释一下吗?

你可以在这里看到http://bit.ly/1vUX8pf

在本例中,出现故障的是最上面的计数器。代码是从底部的计数器稍微改编过来的,它继续工作得很好。说我感到困惑是轻描淡写的!

完整代码如下:

代码语言:javascript
复制
(function($) {

function audioSecondsInit() {
    $('.nectar-audioseconds').each(function() {
        if($(this).has('[data-symbol]')) {
            if($(this).attr('data-symbol-pos') == 'before') {
                $(this).find('.number').prepend($(this).attr('data-symbol'));
            } else {
                $(this).find('.number').append($(this).attr('data-symbol'));
            }
        }
    });

    if(!$('body').hasClass('mobile')) {
        $('.nectar-audioseconds').each(function() {
            // FAILS HERE >>>
            $(this).waypoint(function(direction) {
                var $endNum = parseInt($(this).find('.number span').text());
                $endNum = $endNum + (23671233 * Math.floor(( (new Date()) - Date.parse('12/01/2014') ) / 86400000));
                $(this).find('.number span').countToFormat({
                    from: 0,
                    to: $endNum,
                    speed: 1500,
                    refreshInterval: 30
                });
            }, { offset: '105%', triggerOnce: true });
        }); 
    }
}
setTimeout(function(){ 
    audioSecondsInit();
},100); 

$.fn.countToFormat = function (options) {
    console.log("countToFormat");
    options = options || {};

    return $(this).each(function () {
        var settings = $.extend({}, $.fn.countTo.defaults, {
            from:            $(this).data('from'),
            to:              $(this).data('to'),
            speed:           $(this).data('speed'),
            refreshInterval: $(this).data('refresh-interval'),
            decimals:        $(this).data('decimals')
        }, options);

        var loops = Math.ceil(settings.speed / settings.refreshInterval),
            increment = (settings.to - settings.from) / loops;

        var self = this,
            $self = $(this),
            loopCount = 0,
            value = settings.from,
            data = $self.data('countTo') || {};

        $self.data('countTo', data);

        if (data.interval) {
            clearInterval(data.interval);
        }
        data.interval = setInterval(updateTimer, settings.refreshInterval);

        render(value);

        function updateTimer() {
            value += increment;
            loopCount++;

            render(value);

            if (typeof(settings.onUpdate) == 'function') {
                settings.onUpdate.call(self, value);
            }

            if (loopCount >= loops) {
                // remove the interval
                $self.removeData('countTo');
                clearInterval(data.interval);
                value = settings.to;

                if (typeof(settings.onComplete) == 'function') {
                    settings.onComplete.call(self, value);
                }
            }
        }
        function render(value) {
            var formattedValue = settings.formatter.call(self, value, settings);
            $self.html(numberWithCommas(formattedValue));
        }
        function numberWithCommas(x) {
           return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        }
    });
};

})(jQuery);
EN

回答 1

Stack Overflow用户

发布于 2014-12-12 00:07:31

在你的网站上,我没有看到waypoint.min.js。

主页,我对它进行了调试,发现它在函数的第一次处理时出错,因为.waypoint不存在。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27427090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档