[問題] 用javascript動態建立CSS

看板Web_Design作者 (專長太多也是一種困擾)時間16年前 (2009/11/01 13:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
我用javascript動態建立CSS, 建立的CSS有發揮作用, 但想alert有多少cssRules,結果是0, 請問各位大大,有人知道為什麼嗎? 以下是程式碼: window.onload = function() { var newStyle=document.createElement('link'); newStyle.setAttribute('type', 'text/css'); newStyle.setAttribute('rel', 'StyleSheet'); newStyle.setAttribute('href', CSS file的路徑); document.getElementsByTagName('head')[0].appendChild(newStyle); alert(document.styleSheets[0].cssRules.length); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.138.32.63
文章代碼(AID): #1AxHciLk (Web_Design)