2016-11-17 9 views
2

を超えて:jqueryのは、私はこのエラーを取得していますなぜ

Uncaught RangeError: Maximum call stack size exceeded

はここに私のコードです:他の人があなたを述べたように

$(document).on('keypress focusout', '.checklist-item-input', function (e) { 
    if (e.which == 13 || e.type == 'focusout') { 
    $('.checklist-item').removeClass('edit'); 
    $(this).siblings('.checklist-item-detail').text($(this).val()); 
    $(this).blur(); 
    $('.checklist-item-detail').each(function() { 
     if (!$(this).text().length) { 
     $(this).closest('.checklist-item').parent().remove(); 
     } 
    }); 
    } 
}); 
+4

「原因)'上げました'.blur()'を呼び出す 'focusout'を呼び出す' .blur() 'を呼び出す' 'focusout'を呼び出す' .blur() 'を呼び出す' 'focusout'を呼び出す' .blur() ....等 –

+2

'$(this).blur();'フォーカスアウトイベントを実行します。無限の時間は –

答えて

0

が効果的に再帰呼び出しを引き起こします。一つの簡単な修正は、それが再帰的に行く停止するセンチネル変数を追加することです:あなたは `.blur(呼び出す` focusout`を提起 `.blur()`を呼び出すfocusout` `上

var busy = false; 
$(document).on('keypress focusout', '.checklist-item-input', function (e) { 
    if (!busy && e.which == 13 || e.type == 'focusout') { 
    busy = true; 
    $('.checklist-item').removeClass('edit'); 
    $(this).siblings('.checklist-item-detail').text($(this).val()); 
    $(this).blur(); 
    $('.checklist-item-detail').each(function() { 
     if (!$(this).text().length) { 
     $(this).closest('.checklist-item').parent().remove(); 
     } 
    }); 
    busy = false; 
    } 
}); 
+0

です。または、 '$(":focus ")'をチェックしてください - http://stackoverflow.com/questions/497094/how-do-i-find-out-dom-element-of-the-focus –

+0

@ freedomn-m:はい、確かに現在のフォーカスをチェックするのにも有効です。 Mineは、あらゆるタイプのイベントに使用される一般的なセンチネルラッパーでした。 –

+0

私はあなたのコードを試みたが、それは私に同じエラーを与える! @GoneCoding –

関連する問題