javascript - 同样的两段JS代码,线上报错,本地运行没问题

查看:257
本文介绍了javascript - 同样的两段JS代码,线上报错,本地运行没问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

做的项目 本地测试没有问题 传到线上就报错

 $(window).bind('scroll', function () {
                var contentmenu_s = $(".contentmenu_s");
                var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                if (scrollTop < _gettopHeight) {
                    top.css("position", "relative");
                    $(".toplist").attr("class", "toplist");
                    $("#fudongnav0 ul li").eq(0).addClass("danghangxuanzhong")
                }
                else {
                    scrollTop += 15;
                    top.css("position", "fixed");
                    $(".toplist").attr("class", "toplist");

                    $("#fudongnav0 ul li").eq(1).addClass("danghangxuanzhong")
                }
                for (var i = 0; i < parseInt($(".toplist").size()) ; i++) {
                    var contentmenu_stop = contentmenu_s.eq(i).offset().top - 60;
                    if (contentmenu_stop < scrollTop) {
                        $(".toplist").attr("class", "toplist");
                        $(".toplist:contains(" + $('.contentmenu_s').eq(i).children('h2').children('span').text() + ")").addClass("danghangxuanzhong");
                    }
                }

            });

线上报Uncaught TypeError: Cannot read property 'top' of undefined错误

解决方案

看代码没有问题,你需要线上浏览器里调试下。看看在哪个i的位置没有找到contentmenu_s.eq(i).offset()

这篇关于javascript - 同样的两段JS代码,线上报错,本地运行没问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆