【发布时间】:2015-09-01 21:44:52
【问题描述】:
我有带有按钮的 HTML 输出。 我想让选定的按钮更改颜色以轻松显示正在查看的部分。
我试图做this thread 中的事情,但没有运气。好像没用过这个功能。
这是一个简单的 html 页面,其中我有按钮并尝试添加功能 focusMe。
<HTML><HEAD>
<STYLE type="text/css">
.btn {
display: inline-block;
border: #2e6da4;
border-style: solid;
border-width: 2px;
width:190px;
height:54px;
border-radius: 6px;
background: linear-gradient(#FFFFFF, #B0B0B0);
font-weight: bold;
color: blue;
margin-top: 5px;
margin-bottom: 5px;
margin-right: 5px;
margin-left: 5px;
vertical-align: middle;
}
.btn:hover {
background: linear-gradient(#152B40, #152B40);
color: white
}
.btn:focus {
background: linear-gradient(#152B40, #152B40);
color: white
}
.button-selected {
border: 4px solid red;
}
</STYLE>
<script type="text/javascript">
function focusMe(button) {
document.getElementsByClassName("button-selected")[0].className = "";
button.className = "button-selected";
}
</script>
</HEAD><BODY>
<div>
<button class='btn'>1</button>
<button class='btn'>2</button>
<button class='btn'>3</button>
<button onClick="focusMe(this);" >4</button>
</div>
</BODY></HTML>
我知道前 3 个按钮不会更改。只是在第 4 个按钮上尝试此功能。
谢谢!
【问题讨论】:
标签: javascript html button colors