Modernizr未定义的未捕获引用错误。

4
我在我的网站上遇到了以下错误:未捕获的引用错误:Modernizr未定义 我正在尝试实现的代码是:https://codepen.io/anon/pen/JyqRpg JQuery代码如下:
jQuery(document).ready(function($){
    //hide the subtle gradient layer (.pricing-list > li::after) when pricing table has been scrolled to the end (mobile version only)
    checkScrolling($('.pricing-body'));
    $(window).on('resize', function(){
        window.requestAnimationFrame(function(){checkScrolling($('.pricing-body'))});
    });
    $('.pricing-body').on('scroll', function(){ 
        var selected = $(this);
        window.requestAnimationFrame(function(){checkScrolling(selected)});
    });

    function checkScrolling(tables){
        tables.each(function(){
            var table= $(this),
                totalTableWidth = parseInt(table.children('.pricing-features').width()),
                tableViewport = parseInt(table.width());
            if( table.scrollLeft() >= totalTableWidth - tableViewport -1 ) {
                table.parent('li').addClass('is-ended');
            } else {
                table.parent('li').removeClass('is-ended');
            }
        });
    }

    //switch from monthly to annual pricing tables
    bouncy_filter($('.pricing-container'));

    function bouncy_filter(container) {
        container.each(function(){
            var pricing_table = $(this);
            var filter_list_container = pricing_table.children('.pricing-switcher'),
                filter_radios = filter_list_container.find('input[type="radio"]'),
                pricing_table_wrapper = pricing_table.find('.pricing-wrapper');

            //store pricing table items
            var table_elements = {};
            filter_radios.each(function(){
                var filter_type = $(this).val();
                table_elements[filter_type] = pricing_table_wrapper.find('li[data-type="'+filter_type+'"]');
            });

            //detect input change event
            filter_radios.on('change', function(event){
                event.preventDefault();
                //detect which radio input item was checked
                var selected_filter = $(event.target).val();

                //give higher z-index to the pricing table items selected by the radio input
                show_selected_items(table_elements[selected_filter]);

                //rotate each pricing-wrapper 
                //at the end of the animation hide the not-selected pricing tables and rotate back the .pricing-wrapper

                if( !Modernizr.cssanimations ) {
                    hide_not_selected_items(table_elements, selected_filter);
                    pricing_table_wrapper.removeClass('is-switched');
                } else {
                    pricing_table_wrapper.addClass('is-switched').eq(0).one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {        
                        hide_not_selected_items(table_elements, selected_filter);
                        pricing_table_wrapper.removeClass('is-switched');
                        //change rotation direction if .pricing-list has the .bounce-invert class
                        if(pricing_table.find('.pricing-list').hasClass('bounce-invert')) pricing_table_wrapper.toggleClass('reverse-animation');
                    });
                }
            });
        });
    }
    function show_selected_items(selected_elements) {
        selected_elements.addClass('is-selected');
    }

    function hide_not_selected_items(table_containers, filter) {
        $.each(table_containers, function(key, value){
            if ( key != filter ) {  
                $(this).removeClass('is-visible is-selected').addClass('is-hidden');

            } else {
                $(this).addClass('is-visible').removeClass('is-hidden is-selected');
            }
        });
    }
});

该页面的地址为:http://ws.nvanderlit.com/index.php/hosting/ 请问有人知道这个错误是什么原因导致的,以及我该如何修复它吗?
提前感谢!

你能展示一下导入modernizr的代码吗?这里有一个关于modernizr的介绍,或许会有所帮助:https://hacks.mozilla.org/2012/07/the-web-developer-toolbox-modernizr/ - Schwesi
http://codebins.com/bin/4ldqom4 - Patrick is nat
你是否从文件中引入了Modernizr?如果路径指向modernizr-custom.js文件,那么<script src="modernizr-custom.js"></script>就可以正常工作。 - Schwesi
现代化定制文件modernizr-custum.js位于我的FTP上/webspace/httpdocs/ws.nvanderlit.com,与index.html文件位于同一位置。这是正确的,不是吗? - Patrick is nat
2个回答

3

您没有正确加载modernizr,请将<script src="modernizr-custom.js"></script>更改为<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>


你可以尝试将这行代码放在闭合的 </head> 标签前面,然后告诉我错误是否仍然存在? - Schwesi
就是那样。 - Schwesi
我仍然收到相同的错误,有没有可能是我们做错了其他地方?比如将modernizr-custom.js文件放错文件夹了。 - Patrick is nat
你的代码中有很多错误。我不太确定为什么它不起作用。我使用你的代码创建了一个 fiddle,并将 modernizr 导入其中。你的代码中存在未关闭的标签等问题,因此很难进行调试:https://jsfiddle.net/u7y8hv35/1/ - Schwesi

2

您是否尝试插入此脚本:

<script src="modernizr-custom.js"></script> 

在插入你的js文件之前,先插入Modernizr脚本。如果Modernizr脚本在当前js文件之后,那么它会导致你的js文件无法识别。请注意保留html标签。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接