简体   繁体   English

什么是最大调用堆栈大小超出错误以及如何解决?

[英]What's a maximum call stack size exceeded error and how to fix it?

I was trying to make a list where the user can add his or her favorites. 我试图列出用户可以添加他或她的收藏夹的列表。 But then I got a "maximum call stack size exceeded" error. 但是随后出现“超出最大调用堆栈大小”错误。

What is that and how do I fix it? 那是什么,我该如何解决?

I'd appreciate the help, thank youuu 感谢您的帮助,谢谢

Here are the codes that I used: 这是我使用的代码:

    <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>

So you have come to StackOverflow to ask what a stack overflow is? 因此,您来到StackOverflow询问什么是堆栈溢出?

Distilling it down to just the onload it is still happening. 将其精简为仅在加载时仍在进行。 Onload is calling itself in an unending recursive loop causing a stack overflow. Onload在无休止的递归循环中调用自身,导致堆栈溢出。

 <!DOCTYPE html> <html> <head> </head> <body onload="onload();"> </body> </html> 

But adding an onload function fixes it. 但是添加onload函数可以解决此问题。

 <!DOCTYPE html> <html> <head> <script> function onload() { console.log('Onload called'); } </script> </head> <body onload="onload();"> </body> </html> 

The Maximum call stack size exceeded. Maximum call stack size exceeded. appears when you enter something like an infinite loop of function! 当您输入诸如功能无限循环之类的内容时,将出现!

Check a better example here 在这里检查一个更好的例子

In your <body> you are typing: onload="onload();" 在您的<body>您输入: onload="onload();" and that's the reason of your problem because onload is calling itself, over and over. 这就是您出现问题的原因,因为onload自我调用。 Try to remove it from your code, and the error will be disappeared. 尝试将其从代码中删除,该错误将消失。

Welcome to StackOverflow! 欢迎来到StackOverflow!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM