2009-08-04 73 views
0

之前我有jQuery的一個問題,我的代碼看起來不錯,但我發現了一個錯誤,這聽起來像這樣:jQuery丟失;聲明

丟失;聲明 前[此錯誤BREAK]} ELSEIF($(」 v_gallery李:第一 ')hasClass(' S')){\ n

我的代碼如下所示:

_gallery_pag:函數(){
$( '#top_pag一個')生活( '點擊',函數(){VAR _type = $(本).attr( '相對');

 switch(_type) 
     { 
      case '1': 
       if($('.v_gallery li:last').hasClass('s')) 
       { 
        $('.v_gallery li:first').find('a').click(); 
       }elseif($('.v_gallery li:first').hasClass('s')){ 
        alert('You can\'t go back!You are at the first page!'); 
       } 
      break; 
     } 
     return false; 
    });  
} 

我知道,可能我想念拼寫檢查因爲我沒有看到任何問題。

10x guys

回答

2

你寫elseif的,而不是「否則,如果」它應該是「如果其他人」 - 在JavaScript中,這是兩個不同的關鍵字。

這裏是你的固定碼:

_gallery_pag : function() { 
$('#top_pag a').live('click',function() { var _type = $(this).attr('rel'); 

       switch(_type) 
       { 
         case '1': 
           if($('.v_gallery li:last').hasClass('s')) 
           { 
             $('.v_gallery li:first').find('a').click(); 
           }else if($('.v_gallery li:first').hasClass('s')){ 
             alert('You can\'t go back!You are at the first page!'); 
           } 
         break; 
       } 
       return false; 
     });    
} 
1

你拼錯別的如果。在else和if之間添加一個空格。

1

「elseif的」是不是在JavaScript中的關鍵字,