[英]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.