求javascript大神,点击按钮改变页面的脚本有点问题
我需要用javascript做一个点击按钮就会改变页面的脚本,现在脚本上面已经有一个检查星期,让后显示对应内容的脚本,所有点击按钮我也要找到所有星期的id,把他们设置di...
我需要用javascript做一个点击按钮就会改变页面的脚本,现在脚本上面已经有一个检查星期,让后显示对应内容的脚本,所有点击按钮我也要找到所有星期的id,把他们设置display设置为none,再吧点击按钮传过来的参数设置为block,但是我编程出现错误了。求大神。。。。
function load(){
var myDate = new Date();
var day = myDate.getDay();
switch(day){
case 0:
document.getElementById("sunday").style.display="block"
break;
case 1:
document.getElementById("monday").style.display="block"
break;
case 2:
document.getElementId("tuesday").style.display="block"
break;
case 3:
document.getElementById("wednesday").style.display="block"
break;
case 4:
document.getElementById("thursday").style.display="block"
break;
case 5:
document.getElementById("friday").style.display="block"
break;
case 6:
document.getElementById("saturday").style.display="block"
break;
}
}
function find(num){
var getWeek = document.getElementById(num);
var weekGround = new Array("sunday","monday","tuesday","wednesday","thursday","friday","saturday");
for (var i in weekGround){
document.getElementById(weekGround[i]).style.display="none";//卡这步上了
}
}
<li><a href="" onclick=find("monday")>星期一</a></li>
<script type='text/javascript'>
window.onload=load();
</script>//这个 放在最后 展开
function load(){
var myDate = new Date();
var day = myDate.getDay();
switch(day){
case 0:
document.getElementById("sunday").style.display="block"
break;
case 1:
document.getElementById("monday").style.display="block"
break;
case 2:
document.getElementId("tuesday").style.display="block"
break;
case 3:
document.getElementById("wednesday").style.display="block"
break;
case 4:
document.getElementById("thursday").style.display="block"
break;
case 5:
document.getElementById("friday").style.display="block"
break;
case 6:
document.getElementById("saturday").style.display="block"
break;
}
}
function find(num){
var getWeek = document.getElementById(num);
var weekGround = new Array("sunday","monday","tuesday","wednesday","thursday","friday","saturday");
for (var i in weekGround){
document.getElementById(weekGround[i]).style.display="none";//卡这步上了
}
}
<li><a href="" onclick=find("monday")>星期一</a></li>
<script type='text/javascript'>
window.onload=load();
</script>//这个 放在最后 展开
3个回答
展开全部
TypeError: document.getElementById(...) is null
document.getElementById("friday").style.display="block"
你压根就没有这个元素 肯定是报错的。。。
document.getElementById("friday").style.display="block"
你压根就没有这个元素 肯定是报错的。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这段代码有问题
document.getElementById("saturday").style.display 你的DIV里面根本没有style属性, 这里会报错,获取不到style
<!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=GBK" />
<title>无标题文档</title>
<script language="JavaScript">
function load1(){
var myDate = new Date();
var day = myDate.getDay();
var monday = 1;
var tuesday = 2;
var wednesday = 3;
var thursday = 4;
var friday = 5;
var saturday = 6;
var sunday = 0;
alert(day);
/*if (day==0)
document.getElementById("sunday").style.display="block"
else if(day==1)
document.getElementById("monday").style.display="block"
else if(day==2)
document.getElementById("tuesday").style.display="block"
else if(day==3)
document.getElementById("wednesday").style.display="block"
else if(day==4)
document.getElementById("thursday").style.display="block"
else if(day==5)
document.getElementById("friday").style.display="block"
else if(day==6)
document.getElementById("satursday").style.display="block"
}*/
switch(day){
case 0:
document.getElementById("sunday").style.display="block"
break;
case 1:
document.getElementById("monday").style.display="block"
break;
case 2:
document.getElementId("tuesday").style.display="block"
break;
case 3:
document.getElementById("wednesday").style.display="block"
break;
case 4:
document.getElementById("thursday").style.display="block"
break;
case 5:
document.getElementById("friday").style.display="block"
break;
case 6:
document.getElementById("saturday").style.display="block"
break;
}
}
</script>
<body onload="load1();">
<div id="monday" style="display:none;">1</div>
<div id="tuesday" style="display:none;">2</div>
<div id="wednesday" style="display:none;">3</div>
<div id="sunday" style="display:none;">7</div>
<div id="thursday" style="display:none;">4</div>
<div id="friday" style="display:none;">5</div>
<div id="saturday" style="display:none;">6</div>
</body>
</html>
这样就对了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询