我试图制作一个列表,用户可以在其中添加他或她的收藏夹。但是后来我收到了“超出最大调用堆栈大小”的错误。
那是什么,我该如何解决?
我很感激你的帮助,谢谢你
以下是我使用的代码:
<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>
Run Code Online (Sandbox Code Playgroud)
所以你来到 StackOverflow 是为了问什么是堆栈溢出?
将其提炼成它仍在发生的加载。Onload 在无休止的递归循环中调用自身,导致堆栈溢出。
<!DOCTYPE html>
<html>
<head>
</head>
<body onload="onload();">
</body>
</html>Run Code Online (Sandbox Code Playgroud)
但是添加一个 onload 函数可以修复它。
<!DOCTYPE html>
<html>
<head>
<script>
function onload() {
console.log('Onload called');
}
</script>
</head>
<body onload="onload();">
</body>
</html>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13751 次 |
| 最近记录: |