网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
06月05日漏签0天
javascript吧 关注:269,259贴子:906,427
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 8回复贴,共1页
<<返回javascript吧
>0< 加载中...

求帮助啊!为什么每个div的颜色不变啊,<script>中哪有问题啊

  • 只看楼主
  • 收藏

  • 回复
  • jiaoheida
  • null
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>变色div</title>
<style>
<script>
var colors=Array("#ffff00","#ff3300","#ff3399","#ff00ff","#99ff00","#66ffff","#33ff33","#00ff33","#0000cc","#990099","#000000","#996600","#0000ff","#666699","#6699ff","#006600","#ff9966","#cc0033","#ccffff","#99ff00","#ccff00","#ffcc00","#330000");
function changecolor()
{
index=Math.floor(Math.random()*colors.length);
document.getElementById("a").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("b").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("c").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("d").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("e").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("f").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("g").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("h").style.backgroundColor=colors[index];
index=Math.floor(Math.random()*colors.length);
document.getElementById("i").style.backgroundColor=colors[index];
}
setTimeout("changecolor()",500);
window.onload=show();
</script>
.da{
width:790px;
height:895px;
}
.a{
height:40px;
width:400px;
background-color:#99ff00;
margin-left:30px;
float:left;
}
.i{
height:410px;
width:40px;
background-color:#00ffff;
margin-right:10px;
margin-bottom:-10px;
float:right;
}
.cc{
height:40px;
width:800px;
}
.b{
height:359px;
width:40px;
background-color:#990099;
margin-bottom:-9px;
margin-left:390px;
}
.aa{
height:40px;
float:left;
margin-left:30px;
}
.c{
height:40px;
width:350px;
background-color:#993300;
float:left;
margin-top:10px;
}
.d{
height:40px;
width:40px;
background-color:#ffff00;
margin-left:10px;
margin-top:10px;
float:left;
}
.e{
height:40px;
width:350px;
background-color:#ff0000;
margin-left:10px;
margin-top:10px;
float:left;
}
.bb{
height:440px;
float:left;
}
.f{
height:440px;
width:40px;
background-color:#0033cc;
margin-left:30px;
margin-top:10px;
float:left;
}
.blank2{
width:320px;
height:400px;
float:left;
}
.g{
height:390px;
width:40px;
margin-top:20px;
background-color:#ff3399;
float:left;
}
.h{
width:400px;
height:40px;
margin-top:410px;
background-color:#00ff00;
margin-left:390px;
}
</style>
</head>
<body>
<div class="da">
<div class="cc">
<div class="a"></div>
<div class="i"></div>
</div>
<div class="b"></div>
<div class="aa">
<div class="c"></div>
<div class="d"></div>
<div class="e"></div>
</div>
<div class="bb">
<div class="f"></div>
<div class="blank2"></div>
<div class="g"></div>
<div class="h"></div>
</div>
</div>
</body>
</html>


  • harusamei
  • true
    4
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
你的DIV没有ID, 而你使用的getElementById 试图获得DIV结点


2025-06-05 07:51:42
广告
  • phpwebasd
  • ifelse
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
你还得把“.”改成“#”


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 8回复贴,共1页
<<返回javascript吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示