簡體   English   中英

什么是最大調用堆棧大小超出錯誤以及如何解決?

[英]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.

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