2010-08-06 10 views
0

버튼이 있고 마우스를 가져갈 때 색상이 바뀝니다. 하지만 다른 버튼이 찰칵 소리를 내며 끌릴 때까지 마우스를 올리면 변경된 색상의 버튼을 유지하려고합니다. 나는 게시물을 읽고 그것은 : focus를 사용한다고 말했지만 이것은 mouseover 일이 아니라 버튼을 클릭 할 때만 작동하는 구현입니다.호버 켜기 색상 변경

도움을 주시면 감사하겠습니다.

답변

2
html: 
<a class="test" href="#" onmouseover="changeColor(this);">test</a> 
<a class="test" href="#" onmouseover="changeColor(this);">test2</a> 

js/jquery: 
function changeColor(obj) { 
    $('.test').css({background:"none"}); 
    obj.style.backgroundColor="green"; 
} 
+0

좋아, 이건 간단했다, 고마워. 나는이 함수를 이해하고, 함수를 작성하는 방법을 더 잘 이해하고있다. –

4

여기에 jQuery를에 그것을 할 방법은 다음과 같습니다

$('.button').mouseover(function(event) { // mouseOver event on all buttons with class .button 
    $('.button').css({background:"green"}); // reset all buttons' color to default green 
    $(event.target).css({background:"red"}); // change current button color to red 
}); 
+0

$ (이) .CSS가 ({배경 : "빨간색"})'사용하지 않을 것이다''$를 사용하는 것보다 더 좋은 수 (event.target) .css ({background : "red"});'? – Potherca