老师帮我找一下代码问题出在哪里了
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onchange()</title>
<style type="text/css">
#div{
width:300px;
height:300px;
border:2px solid gray;
margin:100px 0 0 200px;
}
</style>
<script type="text/javascript">
window.load=function(){
var userColor=document.getElementById("color"),
element=document.getElementById("div");
userColor.onchange=function(){
var getColor=this.value,
getColor1=userColor.option[userColor.selectedIndex].value,
getColor2=userColor.value;
console.log(getColor)
if(userColor=="0"){
this.style.background="white";
element.innerHTML="我没有发生任何变化";
}else{
this.style.background=getColor;
element.innerHTML="我的背景颜色变成了"+getColor+"色";
}
}
}
</script>
</head>
<body>
<div>
<span>请选择您喜欢的颜色:</span>
<select id="color">
<option value="0">请选择</option>
<option value="yellow">黄色</option>
<option value="orange">橘色</option>
<option value="pink">粉色</option>
<option value="purple">紫色</option>
</select>
</div>
<div id="div">我是div</div>
</body>
</html>9
收起
正在回答 回答被采纳积分+1
2回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星