我想实现的效果是,点击按钮后,按钮的背景颜色改变,但是我测试和更改了很多次,背景色没有任何改变, 10
<html><head><title></title><scripttype="text/javascript">document.getElementById('btn...
<html >
<head>
<title></title>
<script type="text/javascript">
document.getElementById('btn').onclick=function(){
document.getElementById('btn').style.background='red';
};
</script>
<style type="text/css">
#haha{background: coral;
width: 100px;
height: 100px;
background: #f00;
}
</style>
</head>
<body>
<div id="haha"></div>
<input type="button" name="btn" id="btn" value="点击测试" />
</body>
</html> 展开
<head>
<title></title>
<script type="text/javascript">
document.getElementById('btn').onclick=function(){
document.getElementById('btn').style.background='red';
};
</script>
<style type="text/css">
#haha{background: coral;
width: 100px;
height: 100px;
background: #f00;
}
</style>
</head>
<body>
<div id="haha"></div>
<input type="button" name="btn" id="btn" value="点击测试" />
</body>
</html> 展开
1个回答
2016-12-20
展开全部
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
window.onload=function(){
document.getElementById('btn').onclick=function(){
fn1(1)
};
function fn1(a){
document.getElementById('btn').style.background="red";
};
};
</script>
<style type="text/css">
#haha{
background: coral;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="haha"></div>
<input type="button" name="btn" id="btn" value="点击测试" />
</body>
</html>
你试试!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询