简体   繁体   English

单击时弹出无法打开Uncaught TypeError:无法读取未定义的属性“ top”

[英]popup on click not open Uncaught TypeError: Cannot read property 'top' of undefined

I face a situation where google chrome returns 我遇到了谷歌浏览器返回的情况

Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义的属性“ top”

This is my jquery code 这是我的jQuery代码

$(document).on('click', '.show_popup', function(){
    document.body.style.overflow = "hidden";
    $('body').css('overflow', 'hidden');    
    callAjax($(this).attr('href'), 'mode=ajax', function(t){
        $('.popup-screen').html(t);
        $('.main-overlay').show();

        // $('').raty();
        $('#star').raty({
          click: function(score, evt) {
            $('#review_rating').val( score);
          }
        });
        // window.scroll(0,0);
        $("html, body").animate({ scrollTop: $(".screenTable").offset().top },500);
    });
    return false;
});

Please help and also after error at 请帮助,并在出现错误后也可以在

XMLHttpRequest.self.xmlHttpReq.onreadystatechange XMLHttpRequest.self.xmlHttpReq.onreadystatechange

This error is showing up because element with class .screenTable could not be found. 由于找不到类.screenTable元素而显示此错误。

You can check the existence of element before calling top to prevent error 您可以在调用top之前检查元素的存在以防止错误

    var STable = $('.screenTable');
    if (STable.length) //1
    { 
      $("html, body").animate({ scrollTop: $(".screenTable").offset().top },500);
      alert("top");
    }
    else{
    alert("element not found, so no top");
    }

Always wrap your function under $( document ).ready() More info on document.ready 始终将函数包装在$( document ).ready()

$( document ).ready(function() {

//All elements has been loaded and are available.

});

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

相关问题 未捕获的类型错误:无法读取未定义的属性“顶部” - Uncaught TypeError: Cannot read property ‘top’ of undefined 未捕获的TypeError:无法读取未定义的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的类型错误:无法读取未定义的属性“顶部” - Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义的属性“ open” - Uncaught TypeError: Cannot read property 'open' of undefined 未捕获的类型错误:无法读取未定义的属性“点击” - Uncaught TypeError: Cannot read property 'click' of undefined 单击时出现 jQuery 错误->未捕获的类型错误:无法读取未定义的属性“顶部” - Getting jQuery error on click -> Uncaught TypeError: Cannot read property 'top' of undefined 购物车飞未捕获的TypeError:无法读取未定义的属性“顶部” - Cart to Fly Uncaught TypeError: Cannot read property 'top' of undefined 图表 JS 错误:未捕获的类型错误:无法读取未定义的属性“顶部” - Chart JS Error : Uncaught TypeError: Cannot read property 'top' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM