如下是我学习时写的代码,但是一运行网页JS里面的那几个按钮事件就自动运行了,不知道我哪里搞错了,我在百度上找了看到按钮事件是像这样写的呀。请大能帮帮小弟,看小弟是哪里搞错了,谢谢哈。
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
<style>
div{
width: 200px;
height: 200px;
background: #998820;
}
</style>
<script>
window.onload = function(){
var oBut_1=document.getElementById('obut_1');
var oBut_2 = document.getElementById('obut_2');
var oBut_3 = document.getElementById('obut_3');
function Gored(odiv_qu, property, price, shebiao){
var oDiv = document.getElementById(odiv_qu);
oDiv.style.background = shebiao;
oDiv.style[property] =price;
}
alert(oBut_1);
oBut_1.onclick = alert("sdsd");
oBut_1.onclick=Gored('oDiv_s', 'width', '25rem', 'green');
oBut_2.onclick=Gored('oDiv_s', 'height', '15rem', '#003320');
oBut_3.onclick=Gored('oDiv_s',' ', ' ', '#022545');
}
</script>
</head>
<body>
<input id="obut_1" type="button" value="变红" />
<input id="obut_2" type="button" value="变绿" />
<input id="obut_3" type="button" value="变黑" />
<div id="oDiv_s"></div>
</body>
</html>
肥皂起泡泡
精慕HU
宝慕林4294392
相关分类