2009-06-09 12 views
0

5クリック機能を1つに変換するにはどうすればよいですか?例えば5クリック機能を値を変更して1つに変換するには

$("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

関連する問題