javascript例子解答

来源:百度知道 编辑:UC知道 时间:2024/06/20 07:15:01
在下面的(这里补充)补上缺少的代码。在下列的程序中,用户可以点击红色,绿色等按钮改变其上方层的背景色。(有三个按按钮的 分别是red green blue)
<html>
<head>
<title>demo</title>
<style type="text/css">
<!--other code-->
#d{border:1px solid gray;width:300px;height:100px;font-size:2em;}
.Red{background:red;}
.Green{background:green;}
.Blue{background:blue;}
<!--other code-->
</style>
<style type="text/javascript">
function cRed(){
var wDiv=(这里补充) ;
wDiv.className="Red";
}
</style>
</head>
<body>
<h3>点击层下面的按钮,可以设置相应的背景色</h3>
<div id="d">DIV Elements</div><br/>
<input type="button" value="red" (这里补充)/>
<!--other code-->
</body>
</html>

<html>
<head>
<title>demo</title>
<style type="text/css">
<!--other code-->
#d{border:1px solid gray;width:300px;height:100px;font-size:2em;}
.Red{background:red;}
.Green{background:green;}
.Blue{background:blue;}
<!--other code-->
</style>
<style type="text/javascript">
function cRed(){
var wDiv=(这里补充) ;
wDiv.className="Red";
}
</style>
</head>
<body>
<h3>点击层下面的按钮,可以设置相应的背景色</h3>
<div id="d">DIV Elements</div><br/>
<input type="button" value="red" onclick="javascript:document.getElementById('d').className='Red'"/>
<input type="button" value="green" onclick="javascript:document.getElementById('d').className='Green'"