Re: [問題] 如何得知訊窗元件裡的資訊

看板Web_Design作者 (Benny)時間19年前 (2006/08/25 11:48), 編輯推噓3(300)
留言3則, 2人參與, 最新討論串4/4 (看更多)
※ 引述《terrybob (翔翔)》之銘言: : ※ 引述《bennylu (Benny)》之銘言: : : <script> : : alert(document.getElementById('LayerBull').style.top); : : </script> : 剛剛的推文問題,找到原因了 : 因為我的css樣式表是用連結的…↓ : <link href="1.css" rel="stylesheet" type="text/css"> : = =如果css設定是在網頁中的話,而不是連結css樣式表裡,就可以讀到… : 有辦法讀到樣式表裡的資料嗎? > <" : 抱歉,問題多… : ↓網頁中的id ↓樣式表中的 : <div id="LayerBull" class="Bulletin">....(asp程式所產生的表格)...</div> : 請大家幫忙…感謝~(敬禮) 如果一定要用<link>來引入*.css style.css -- .divCSS{ position:absolute; top:40px; } *.htm -- <link rel="stylesheet" type="text/css" href="style.css" /> <script> function getMyStyle(id,property){ element=document.getElementById(id); if(document.all){ alert(element.currentStyle[property]) }else{ cs=document.defaultView.getComputedStyle(element,null); alert(eval("cs."+property)); } } </script> <div id="obj" class="divCSS"> text </div> <input type="button" value="position" onclick="getMyStyle('obj','position')" /> <input type="button" value="top" onclick="getMyStyle('obj','top')" /> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.7.82 ※ 編輯: bennylu 來自: 220.132.7.82 (08/25 12:06)

08/25 12:20, , 1F
執行結果:document.defaultView是null…@@"我作錯了嗎?
08/25 12:20, 1F
※ 編輯: bennylu 來自: 220.132.7.82 (08/25 12:48)

08/25 12:49, , 2F
文章已修改 :)
08/25 12:49, 2F

08/25 13:15, , 3F
成功了。感謝…> <
08/25 13:15, 3F
文章代碼(AID): #14xdBzWc (Web_Design)
討論串 (同標題文章)
文章代碼(AID): #14xdBzWc (Web_Design)