所以,这在我的脑海中似乎很容易做到,但我无法让它工作,谷歌也没有帮助我,你能看到我做错了什么吗?
我有 5 个 div,我希望它们与浏览器窗口的高度相同。即使在调整大小。
这是我的代码:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function setDivHeight(){
var windowHeight = window.innerHeight;
if(windowHeight > 400){
document.getElementsByClassName("minHeight").style.backgroundColor = 'black';
}
else if(windowHeight < 400){
document.getElementsByClassName("minHeight").style.backgroundColor = 'red';
}
}
window.addEventListener("resize",setDivHeight,false);
</script>
</head>
<style type="text/css">
body{margin:0; padding:0;}
.minHeight{
height:20px;
}
.a{
background: #09C;
}
.b{
background: #09b;
}
.c{
background: #09d;
}
.d{
background: #09e;
}
.e{
background: #09f;
}
</style>
<body onload="setDivHeight()">
<div class="a minHeight"></div>
<div class="b minHeight"></div>
<div class="c minHeight"></div>
<div class="d minHeight"></div>
<div class="e minHeight"></div>
</body>
</html>