1
我真的想通過使用switch語句保持我的代碼清潔,但它似乎不工作一些方法。我已經有該類.ClientButtonPic
對象的數組,如果我寫開關語句不能與點擊事件
var clientButtonNumber = $(".ClientButtonPic");
$(clientButtonNumber[0]).click(function(){ $(".ClientImages:eq(0)").fadeIn(300);
$(".ClientImages:eq(1)").fadeOut(300); });
它正常工作,但因爲我有6個實例,可以點擊我想用switch語句。我的繼承人代碼:
var clientButtonNumber = $(".ClientButtonPic");
$(clientButtonNumber).click(function(){
switch(this)
{
case 0:
$(".ClientImages:eq(0)").fadeIn(300);
$(".ClientImages:eq(1)").fadeOut(300);
break;
case 1:
$(".ClientImages:eq(1)").fadeIn(300);
$(".ClientImages:eq(0)").fadeOut(300);
break;
default:
break;
}
});
任何幫助表示讚賞。
'this'是發起事件的DOM對象。它不匹配0,1,2等數字。 – jfriend00 2012-04-10 04:51:49