2014-03-19 76 views
0

嗯,這是我的代碼,我試圖添加到輸入按鈕的選項卡行爲(當我點擊輸入,下一個輸入將重點)。「Uncaught RangeError:最大調用堆棧大小超過」java環境primefaces

當我按下回車鍵時,出現一個Uncaught RangeError。 我嘗試了一切,但沒有改變。

環境:JavaEE(primefaces)。 jQuery的。

function ifNotTextPass(selector) { 
    if (selector.next().is('input[type="text"]')) { 
     alert('yes'); 
     selector.next().focus(); 
    } else { 
     if (selector.next() !== null) { 
      ifNotTextPass(selector.next()); 
     } 
    } 
} 

$(document).ready(function() { 
    $('input[type="text"]').keypress(function (e) { 
     if (e.keyCode === 13) { 
      ifNotTextPass($(this)); 
     } 
    }); 
}); 
+0

不可以,遞歸循環連續執行,以便發生錯誤。請停止循環或打破 –

回答

0

問題是:對函數的無限調用,它就像無限循環。

我改變了整個代碼結構。我已經到達解決方案沒有得到任何錯誤。

此代碼將給出與輸入按鈕相同的Tab按鈕行爲。加上它將只關注文本和textareas。

$(document).on('keydown', 'input[type="text"],textarea', function(e) { 
      var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; 

      if(key === 13) { 
       e.preventDefault(); 
       $(this).focus(); 
       var inputs = $(this).parents('body').find(':input[type="text"]:enabled:visible:not("disabled"),textarea'); 

       inputs.eq(inputs.index(this)+ 1).focus(); 
       inputs.eq(inputs.index(this)+ 1).click(); 

       e.preventDefault(); 
       e.stopPropagation(); 
      } 
}    
0

一個jQuery選擇器永遠不會返回null,所以你有遞歸直到堆棧溢出。試試這個:

if (selector.next().length) { 
+0

好,即使我把它關掉,它也會顯示相同的問題 –

+0

你能否創建一個演示問題的小提琴? –

相關問題