<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>彈出DIV層,可選擇遮罩當前或所有頁面 - Liehuo.Net</title> <meta charset="gbk" /> <style> div{position:absolute;top:0;left:0;background:#ccc;} </style> </head> <body> <div id="zhezhao"></div> <input type="button" value="蓋住整個頁面"/> <input type="button" value="蓋住可視的部分"/> <p style="height:1800px;"></p> </body> </html> <script> function zhezhao(f){ var d = document.getElementById('zhezhao'),wh = getWH(f); d.style.cssText +=";width:"+wh.w+'px;height:'+wh.h+'px' } var getWH = function (){ var d = document,doc = d[d.compatMode == "CSS1Compat"?'documentElement':'body']; return function(f){ return { w:doc[(f?'client':'scroll')+'Width'], h:f?doc.clientHeight:Math.max(doc.clientHeight,doc.scrollHeight) } } }() </script>