2017-05-31 38 views
0

以下功能在我的瀏覽器的控制檯窗口中拋出一個錯誤頁面加載時:引導3 jQuery的偏移JavaScript錯誤

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

你運行在DOM準備的代碼? – gaetanoM

回答

1

基本上(不看到相關的HTML)你想獲得的偏移量元素,不存在:

$('[data-toggle="popover"]')

+0

它引用了我在下載的模板中沒有使用的元素。謝謝! –