Uncaught TypeError: Cannot read property of undefined In JavaScript
當指令碼遇到未初始化的變數或物件時,通常會丟擲如上圖所示的錯誤。
Decription
'Undefined'是全域性物件的屬性。如果沒有為變數賦值,則為'undefined'型別。當求值變數沒有任何賦值時,程式碼也會返回未定義的值。
Code structure
function test(t) { //defining a function if (t === undefined) { //if t=undefined, call tt console.log(t.tt) //call tt member from t} return t; } var a; //a is a variable with undefined value console.log(test(a)); //function call
Error
執行以上程式碼後,將會看到一個錯誤提示:
Debugging
需要在程式碼中判斷是否變數是 undefined
if (typeof(jsvariable) == 'undefined') { ... }
https://codeburst.io/uncaught-typeerror-cannot-read-property-of-undefined-in-javascript-c81e00f4a5e3
相關推薦
Uncaught TypeError: Cannot read property of undefined In JavaScript
當指令碼遇到未初始化的變數或物件時,通常會丟擲如上圖所示的錯誤。 Decription 'Undefined'是全域性物件的屬性。如果沒有為變數賦值,則為'undefined'型別。當求值變數沒有任何賦值時,程式碼也會返回未定義的值。 Code str
【JavaScript】頁面載入 解決Uncaught TypeError: Cannot set property of undefined at
在初學js的時候,有同學會遇到 Uncaught TypeError: Cannot set property 'onmouseover' of undefined at **.html 的問題 這個問題牽扯到頁面載入順序的問題。 我們知道 頁
jQuery mobile報錯 Uncaught TypeError: Cannot read property 'concat' of undefined
typeerror html error 錯誤 query doctype src mobile scrip 寫一個jQuery mobile的demo <!DOCTYPE html> <html> <head>
一種Uncaught TypeError: Cannot read property 'property' of undefined錯誤的解決辦法
過程 body aaa erro name 跳出循環 記錄 peer query 我有一個名為positionList的js數組。 數組裏面放的是map類型的數據。。 如 { id:1, name:"aaaa" } 當我在遍歷數據的過程中刪除了一個元素後。(用的是j
reportComplaints.js: Uncaught TypeError: Cannot read property 'message' of undefined
port 定義 錯誤 prope urn UNC mil turn peer vonic 中遇到這麽個問題, 一直提示我未定義, 可是明明有定義 var tab={ message:{ number:‘‘, title:‘‘
Uncaught TypeError: Cannot read property 'draw' of undefined
1. 來源自慕課網Daisy 的課程《canvas實現星星閃爍特效》,相關問題下面有我的回答 部分js指令碼如下 function init() { can = document.getElementById("canvas"); &nb
JavaScript出現 Uncaught TypeError: Cannot read property 'innerHTML' of undefined錯誤
原因: 意思就是當前的那個標籤沒有定義,原因是html的執行順序是從上到下,在標籤還沒有載入的時候該方法就被呼叫了, 所以會出沒有定義的錯誤 解決辦法有兩個: 一、最直接的方法就是將JavaScript程式
Uncaught TypeError: Cannot read property 'get' of undefined --echarts.min.js:12
本來是做後端的,公司要求改改前端 用的是echarts。就使用了一段時間。看來我離全棧只差9999步了! 問題是這樣的: 本來公司做的echarts報表很正常 沒什麼問題(以前鄙人也做了一
錯誤碼:Uncaught TypeError: Cannot read property 'field' of undefined
錯誤碼:Uncaught TypeError: Cannot read property ‘field’ of undefined 具體錯誤資訊: Uncaught TypeError: Cannot read property 'field' of undefined
Uncaught TypeError: Cannot read property 'addMethod' of undefined
目錄 1:js 引入順序 2:‘$’ 衝突 出現以上錯誤有倆種情況: 1:js 引入順序 jquery.validate.js 引入的順序一定要在執行$.validator.addMethod()之前引入。 解決方案:保證 jquery.validate.js
Uncaught TypeError: Cannot read property 'addMethod' of undefined
目錄 出現以上錯誤有倆種情況: 1:js 引入順序 jquery.validate.js 引入的順序一定要在執行$.validator.addMethod()之前引入。 解決方案:保證 jquery.validate.js 優先引入。 2:‘$’ 衝突 當
關於Uncaught TypeError: Cannot read property 'toLowerCase' of undefined的問題
今天我在處理表單時根據觸發事件動態獲取input中的value值,我是直接在html程式碼中設定響應函式,函式中用jquery的$(this).val()獲取物件的value,結果控制檯報出如標題所示的錯誤,這我就納了悶了,怎麼會這樣,甚是糾結,上網一查排在前的
怎麼解決jQuery的Uncaught TypeError: Cannot read property 'init' of undefined這個問題
function initZtree(){ $.ajax({ url:"assetType_querytype.action", data:'', dataType:'json', type:'post'
datatables表格外掛(1) Uncaught TypeError: Cannot read property 'length' of undefined錯誤分析
前端小白,第一次接觸Datatables表格外掛,經常會遇到Uncaught TypeError: Cannot read property ‘length’ of undefined這麼個報錯 我也遇到了好幾次,每次都沒記住,幾天狠下心來寫一篇推文,分享給大家
Uncaught TypeError: Cannot read property 'trigger' of undefined(zepto.js)
去掉pointermove pointerdown pointerstart 原因: 點選tap,touchstart和pointerstart都執行了,tap裡面程式碼執行了兩次,仔細看了下,首先點選後觸發了兩次,說明被綁定了兩次事件,然後檢視下zepto的touch.js程式碼,發現
easyui使用時出現這個Uncaught TypeError: Cannot read property 'combo' of undefined
easyui使用時出現這個Uncaught TypeError: Cannot read property 'nodeName' of undefined 最後檢查發現是必須給select一個id,光給name不行, 構建後,easyui改變了dom結構,元素的訪問
jquery.dataTables.min.js:62 Uncaught TypeError: Cannot read property 'style' of undefined原因
maven/java/web/bootstrapQQ群:566862629。希望更多人一起幫助我學習。 報錯: jquery.dataTables.min.js:62 Uncaught TypeError: Cannot read property 'style' of
SignalR代理物件異常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的結論
後臺建立了一個DntHub的集線器 前臺在呼叫的時候出現了問題(經檢查是代理物件建立失敗) 於是到StackOverflow上面找了下: 上面說改成小寫就ok了,很多人也解決成功了 逆天改成小寫後也解決了,var chat = $.connection.dntHub 也許很多人就直接
記錄一個bootstrap因js載入順序導致的問題(tstrap-table-mobile.min.js:7 Uncaught TypeError: Cannot read property 'defaults' of undefined)
問題描述: 網上找了會沒看到答案,然後看了下原始碼,發現也沒有問題,想到js載入的順序,改了下,發現問題沒了。 正確的順序: 我之前把 <script src="/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></sc
使用form的方法(例如:reset,clear等)報錯Uncaught TypeError: Cannot read property 'tip' of undefined(…)的原因
在瀏覽器中debug前端程式碼時,第一次按一個按鍵,沒有問題,第二次開始再按這個按鍵的時候,出現了錯誤Uncaught TypeError: Cannot read property 'tip' of undefined(…),雖然不影響功能,但是出現紅色的錯誤總是感覺