[問題] 關於div的顯示與隱藏

看板Web_Design作者 (TypeZero)時間16年前 (2009/03/07 15:37), 編輯推噓2(207)
留言9則, 4人參與, 最新討論串1/1
目前我是這樣寫得: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文件</title> <style type="text/css"> <!-- .div001 { visibility: hidden; } --> </style> <script type="text/javascript"> <!-- function MM_showHideLayers() { //v9.0 var i,p,v,obj,args=MM_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; } obj.visibility=v; } } //--> </script> </head> <body> <p onclick="MM_showHideLayers('001','','show')">打開</p> <div class="div001" id="001">test</div> </body> </html> 但是這樣寫有一個缺點,就是當div高度很高時,就算隱藏也會把外圍的表格撐開 於是我嘗試用 display: none; 的方式隱藏他(div預設隱藏) 然後將onClick的地方改成下面這樣 onClick="document.getElementById('001').style.display='';" CSS的地方改成這樣: .div001 { visibility: hidden; display: none; } 不過沒有效果,點下去東西還是消失狀態...囧! 於是我把上面那句onClick改成 onClick="document.getElementById('001').style.display='inherit'; 問題大部分都解決了(在Google Chrome、FireFox、Opera), 不過這樣在IE 7裡面沒用.... (/‵Д′)/~ ╧╧ 這該怎麼辦呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.46.165.222

03/07 16:05, , 1F
你把id跟class誤用了, 為什麼不直接把id取div001 ?
03/07 16:05, 1F

03/07 16:05, , 2F
id, class的命名絕對不要數字開頭
03/07 16:05, 2F

03/07 16:06, , 3F
如果你寫過任何一種程式語言都應該要有這基本概念才是
03/07 16:06, 3F

03/07 16:11, , 4F
改了 還是一樣@@
03/07 16:11, 4F

03/07 16:16, , 5F
IE對class似乎不太友善 盡量用id
03/07 16:16, 5F

03/07 16:18, , 6F
改成id後 還是一樣所瀏覽器 只有IE沒動作
03/07 16:18, 6F

03/07 16:29, , 7F
IE不吃inherit....
03/07 16:29, 7F

03/07 16:29, , 8F
剛剛刪掉以後就正常了
03/07 16:29, 8F

03/08 14:47, , 9F
display='block'
03/08 14:47, 9F
文章代碼(AID): #19iYHEq0 (Web_Design)