看板 Ajax 關於我們 聯絡資訊
for(var p=0; p<(list.childNodes.length-1);p++){ x=list.childNodes[p].childNodes[4].innerHTML; y=list.childNodes[p+1].childNodes[4].innerHTML; c=list.childNodes[p]; // console.log(c) var x1=x.split(":")[0]; var x2=x.split(":")[1]; var y1=y.split(":")[0]; var y2=y.split(":")[1]; if(Number(x1)>Number(y1)||(Number(x1)==Number(y1)&&Number(x2)>Number(y2))){ shouldSwitch = true; break; } } 測試時 一直出現以下錯誤 Uncaught TypeError: Cannot read property 'innerHTML' of undefined at Object.success (tra.js:354) at fire (jquery-1.12.4.js:3232) at Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362) at done (jquery-1.12.4.js:9840) at XMLHttpRequest.callback (jquery-1.12.4.js:10311) 這該怎麼解決 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.162.125.235 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1574734401.A.211.html
LZN: 把childNode都印出來檢查吧 11/26 11:02
LPH66: 你的 HTML 長怎樣? 11/26 15:30
bakedgrass: console.log印出你的childNode和其parent node,看有 11/27 01:03
bakedgrass: 沒有抓對你要的DOM 11/27 01:03
laechan: 為啥p<(list... 那邊要括號 11/30 00:11
laechan: 就一般code的角度, y=list.childNodes[p+1]這裡會出問題 11/30 00:15
laechan: 喔沒,看錯,沒事 11/30 00:18
joedenkidd: 個人覺得 p+1那行有問題 12/02 08:25
LPH66: 同問貼 HTML 出來, 只看這裡我會猜問題在 childNodes[4] 12/03 23:20
wotupset: 應該是childNodes抓錯了 所以找不到innerHTML屬性 12/04 09:01
wotupset: https://codepen.io/i/full/povvdNo 用$.each比較方便 12/04 23:00
laechan: .each +1, 用慣了就回不去了:p 12/08 01:09