[問題] getElementsByClassName

看板Web_Design作者 (Bruce Chen)時間6年前 (2018/05/11 15:29), 編輯推噓0(009)
留言9則, 5人參與, 6年前最新討論串1/1
我用了 getElementsByClassName 的函數來找出所有 memhead1 的 object 可是 document.getElementsByClassName("memhead1") 有東西 document.getElementsByClassName("memhead1").length 卻是 0 ? 為什麼會這樣呢? Source: https://github.com/BruceChen034020/20180510BugDemo 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.126.66.25 ※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1526023777.A.95C.html

05/11 15:45, 6年前 , 1F
js執行的時候 body都還沒載入 所以抓不到
05/11 15:45, 1F

05/11 16:18, 6年前 , 2F
要怎麼先載入 body 再執行 js ?
05/11 16:18, 2F

05/11 17:02, 6年前 , 3F
<body onload="somefunction();">
05/11 17:02, 3F

05/11 22:31, 6年前 , 4F
最簡單的作法,把javascript放到html內容之後
05/11 22:31, 4F

05/11 22:31, 6年前 , 5F

05/11 22:32, 6年前 , 6F
這樣同時也可以增加網頁出現畫面的速度(總速度不變)
05/11 22:32, 6F

05/11 22:33, 6年前 , 7F
05/11 22:33, 7F

05/11 23:11, 6年前 , 8F
缺了 dom ready 的東西?
05/11 23:11, 8F

05/18 12:45, 6年前 , 9F
解決了,謝謝大家
05/18 12:45, 9F
文章代碼(AID): #1QzKPXbS (Web_Design)