2009-06-09 3 views
0

어떻게 5 클릭 기능을 하나로 변환합니까? 예를 들어5 클릭 기능을 변경 값으로 변환하는 방법

$("div#styleswitcher a.green").click(function(){ 
$("container").css({'background' : 'green'}); 

) 

$("div#styleswitcher a.blue").click(function(){ 
$("container").css({'background' : 'blue'}); 

) 

$("div#styleswitcher a.red").click(function(){ 
$("container").css({'background' : 'red'}); 

) 

$("div#styleswitcher a.yellow").click(function(){ 
$("container").css({'background' : 'yellow'}); 

) 

답변

6

이 마음에 온다 :

$("#styleswitcher a").click(function() 
{ 
    $("container").css("background-color", this.className); 
}); 

가정은 배경색이 예를

+0

좋은 깨끗한 솔루션 같이 클래스 이름이어야한다는 것입니다! – tekBlues

관련 문제