老师帮忙看看这样可行?
来源:3-4 编程练习
鲸落2020
2020-06-28 16:53:56
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>字体颜色变化</title>
<style>
.btn{width: 180px;height:30px;
line-height: 30px;
margin-top: 30px;
text-align: center;
background-color: #333;color: #fff;
border-radius: 5px;
cursor: pointer;
}
</style>
<script>
window.onload=function(){
var col=document.getElementById("btn");
col.onclick=function(){
this.style.color="red";
}
col.onmouseout=function(){
this.style.color="gray"
}}
</script>
</head>
<body>
<input type="button" value="点击改变按钮字体颜色" color="gray"
onclick="this.style.color='red'"
onmouseout="this.style.color='gray'">
<div id="btn" class="btn" type="button" >点击改变按钮字体颜色</div>
</body>
</html>
1回答
同学你好,代码实现效果没有问题,很棒!
优化:标签中默认没有color属性,写上也不会生效,这是css中的,所以可以去掉

祝学习愉快!
相似问题