HTML button变色的js代码
2个回答
推荐于2016-02-16
展开全部
<html>
<head>
<title> New Document </title>
<script>
function abc(obj){
var zhi = document.getElementsByTagName("INPUT");
for(var i=0;i<zhi.length;i++){
zhi[i].style.color="";
}
document.getElementsByTagName("INPUT")[obj-1].style.color="red";
}
</script>
</head>
<body>
<input type="button" value="button1" id="button1" onclick="abc(1)"><br>
<input type="button" value="button2" id="button2" onclick="abc(2)"><br>
<input type="button" value="button3" id="button3" onclick="abc(3)"><br>
<input type="button" value="button4" id="button4" onclick="abc(4)"><br>
<input type="button" value="button5" id="button5" onclick="abc(5)"><br>
</body>
</html>
这样就可以了
<head>
<title> New Document </title>
<script>
function abc(obj){
var zhi = document.getElementsByTagName("INPUT");
for(var i=0;i<zhi.length;i++){
zhi[i].style.color="";
}
document.getElementsByTagName("INPUT")[obj-1].style.color="red";
}
</script>
</head>
<body>
<input type="button" value="button1" id="button1" onclick="abc(1)"><br>
<input type="button" value="button2" id="button2" onclick="abc(2)"><br>
<input type="button" value="button3" id="button3" onclick="abc(3)"><br>
<input type="button" value="button4" id="button4" onclick="abc(4)"><br>
<input type="button" value="button5" id="button5" onclick="abc(5)"><br>
</body>
</html>
这样就可以了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询