如何用jQuery或者js写一个功能,两个按钮input按钮,点击其中一个背景变色,另一个保持本身颜色。

点击第一个背景变色,第二个按钮保持本事颜色。点击第二个按钮,第一个按钮恢复原来颜色,第二个按钮背景变色

<html>
<head>
<title></title>
<meta charset="UTF-8">
</head>
<style type="text/css">


</style>
<body>
<script type="text/javascript">

function sure (key) {
//这些代码是javascript的代码,需要包含在script标签中

/* if(confirm("确认删除?"))
 {
       alert('已删除');
 }
else
{
       alert('取消')
}*/
var bt1 = document.getElementById('bt1');
var bt2 = document.getElementById('bt2');
bt1.style.backgroundColor="";
bt2.style.backgroundColor="";
if(key==1){
bt1.style.backgroundColor="red";
}else if(key==2){
bt2.style.backgroundColor="red";
}
}



</script>


<!-- <input type="button" onclick="sure()" value="删除"> -->
<input type="button" id="bt1" onclick="return sure(1)" value="按钮1">
<input type="button" id="bt2" onclick="return sure(2)" value="按钮2">
</body>
</html>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-02-12
if判断,改变他的backgroup属性不就行了,多简单的
相似回答