以下函数在页面加载时在浏览器的控制台窗口中抛出错误:
function getRight() {
return ($(window).width() - ($('[data-toggle="popover"]').offset().left + $('[data-toggle="popover"]').outerWidth()))
}
错误:
Uncaught TypeError: Cannot read property 'left' of undefined
at getRight (application.js:12)
at HTMLDocument.<anonymous> (application.js:30)
at j (jquery.js:3099)
at Object.fireWith [as resolveWith] (jquery.js:3211)
at Function.ready (jquery.js:3417)
at HTMLDocument.I (jquery.js:3433)
getRight @ application.js:12
(anonymous) @ application.js:30
j @ jquery.js:3099
fireWith @ jquery.js:3211
ready @ jquery.js:3417
I @ jquery.js:3433
该页面正在加载此jQuery:
https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
答案 0 :(得分:1)
基本上(没有看到相关的HTML)您尝试获取偏移量的元素不存在:
$('[data-toggle="popover"]')