[英]What's a maximum call stack size exceeded error and how to fix it?
我试图列出用户可以添加他或她的收藏夹的列表。 但是随后出现“超出最大调用堆栈大小”错误。
那是什么,我该如何解决?
感谢您的帮助,谢谢
这是我使用的代码:
<body onload="onload();">
<!--for everything in the navigation part including the add favorite bar-->
<div class="topnav">
<!--links to the other pages-->
<a class="active" href="home.html">Home</a>
<a href="games.html">Games</a>
<a href="movies.html">Movies</a>
<a href="series.html">TV Series</a>
<a href="books.html">Books</a>
<!--for the add favorite button-->
<div class="addFave">
<!--the text bar-->
<input type="text" name="enter" class="enter" value="" id="added" placeholder= "Add Favorites"/>
<!--the enter button-->
<input type="button" value="Enter" id = "addIt" OnClick="adding()" />
<!--for the script of the add favorite bar to add its functions-->
<script type="text/javascript">
var faves = [];
var y = document.getElementById("added");
function adding() {
faves.push(y.value);
document.getElementById("faveLists").innerHTML = faves;
}
var input = document.getElementById("added");
input.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById("addIt").click();
}
});
</script>
</div>
</div>
<!--for the additional texts-->
<div class="list">
<!--where the user input in the add favorite bar will appear-->
<p id = "faveLists"></p>
</div>
</body>
</html>
因此,您来到StackOverflow询问什么是堆栈溢出?
将其精简为仅在加载时仍在进行。 Onload在无休止的递归循环中调用自身,导致堆栈溢出。
<!DOCTYPE html> <html> <head> </head> <body onload="onload();"> </body> </html>
但是添加onload函数可以解决此问题。
<!DOCTYPE html> <html> <head> <script> function onload() { console.log('Onload called'); } </script> </head> <body onload="onload();"> </body> </html>
Maximum call stack size exceeded.
当您输入诸如功能无限循环之类的内容时,将出现!
在这里检查一个更好的例子
在您的<body>
您输入: onload="onload();"
这就是您出现问题的原因,因为onload
自我调用。 尝试将其从代码中删除,该错误将消失。
欢迎来到StackOverflow!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.