解决Uncaught RangeError: Maximum call stack size exceeded

 解释: 未捕获的范围错误:超过了最大调用堆栈大小  

报错原因:一般是写了一个死循环导致浏览器内存溢出了,比如递归中没有写出口

报错代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Maximum call stack size exceeded test</title>
<script type="text/javascript">
	//点击按钮方法(错误写法)
	function onclick() {
		alert(1);
	}
</script>
</head>
<body>
	<input value="点击" type="button" onclick="onclick()" />
</body>
</html>

解决思路:根据浏览器提示错误代码所在行数,找到这个函数后为其添加出口或调整逻辑

修改函数名(把onclick 修改为onclick1 ):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Maximum call stack size exceeded test</title>
<script type="text/javascript">
	//点击按钮方法(修复之后)
	function onclick1() {
		alert(1);
	}
</script>
</head>
<body>
	<input value="点击" type="button" onclick="onclick1()" />
</body>
</html>

再次运行就可以啦!

猜你喜欢

转载自blog.csdn.net/zz130428/article/details/130622479