簡體   English   中英

錯誤:未處理的異常超出了最大調用堆棧大小

[英]Error: Unhandled exception maximum call stack size exceeded

我寫了一個簡單的代碼:選中一個復選框時顯示一個警報,否則顯示另一個警報。

function test() {
  if (this.view.checkBoxAgree.onSelection() === true) {
    alert("okay");
  } else {
    alert("cancel");
  }
}

但是,我遇到了一個錯誤:

超出未處理的異常的最大調用堆棧大小。

我想這與Eea6有關,但是我對es6不太了解。

看來您正在使用事件onSelection ,這正在創建一個循環,最終使堆棧溢出。 相反,您應該使用諸如checked這樣的屬性。 發布您的HTML代碼,因為我們對this.view.checkBoxAgree因此我們可以為您提供幫助。 這是您在與您相似的層次結構中使用標准格式和復選框來執行的操作:

 function test() { if (this.view.checkBoxAgree.checked === true) { alert("okay"); } else { alert("cancel"); } } 
 <form name="view"> <input type="checkbox" id="checkBoxAgree" onclick="test();" /> Agree </form> 

或者,你就可以將JavaScript中,而不是HTML和訪問直接使用復選框事件this是這樣的:

 document.getElementById("checkBoxAgree").addEventListener("click", function() { if (this.checked === true) { alert("okay"); } else { alert("cancel"); } }); 
 <form name="view"> <input type="checkbox" id="checkBoxAgree" /> Agree </form> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM