:
<script type="text/javascript">
setFocus = function(e) {
if (document.getElementsByClassName('focus')[0]) document.getElementsByClassName('focus')[0].className = '';
if (e.target.tagName.toLowerCase() == 'button') {
e.target.className = 'focus';
}
};
document
.getElementById('container')
.onclick = setFocus;
</script>
내 HTML 마크 업이처럼 보였다 당신은 어떤 버튼을 클릭하면 "이전"이라고 말하는 변수에 저장됩니다.
다른 단추를 클릭하면 저장된 단추 변수 의 색을 변경하고 현재 단추를 해당 변수에 지정합니다.
var previous;
document.getElementsByClassName("className").onclick = function(){
// change the color of the previous element
previous = this;
// change the color of this button
}
하지 매우 효율적 당신이 버튼의 다수가 있습니다. –