日期:2014-05-18  浏览次数:20775 次

关于DIV的问题
动态生一个DIV,要求充满整个可见区,背景为蓝色,当拉动滚动条的时候,整个DIV仍充满整个可见区,也就是说,这个DIV固定不动!(这是一个百度的招聘笔试题)请大家给一个准确答案!

------解决方案--------------------
<html>
<head>
<title> new page </title>
<script>
function a(){
var divObj=document.createElement( " <div> ");
divObj.style.top=0;
divObj.style.left=0;
divObj.style.width=document.body.offsetWidth;
divObj.style.height=document.body.offsetHeight;
divObj.style.position= "absolute ";
divObj.style.backgroundColor= "blue ";
document.body.appendChild(divObj);
document.body.onscroll=function (){
divObj.style.left=document.body.scrollLeft;
divObj.style.top=document.body.scrollTop;
};
document.body.onresize=function (){
divObj.style.width=document.body.offsetWidth;
divObj.style.height=document.body.offsetHeight;
};
}
</script>
</head>
<body onload=a()>
<div style= "width:1500;height:1000 "> </div>
</body>
</html>