javaScript报错后是否会继续执行后面的代码

 javaScript报错后是否会继续执行后面的代码

 

javaScript报错后,在相同的script标签中的js代码,会受到影响;

新的script标签中的js代码,不会受到影响!

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>javaScript报错后是否会继续执行后面的代码</title>
<link rel="stylesheet" type="text/css" href="../css/body.css" />
<link rel="stylesheet" type="text/css" href="../css/mark.css" />
<link rel="stylesheet" type="text/css" href="../css/input2.css" />
<link rel="stylesheet" type="text/css" href="../css/console.css" />
</head>
<body>
<h1>javaScript报错后是否会继续执行后面的代码</h1>
</body>
<script type="text/javascript">
	function fn1() {
		console.log(666); //666
		//故意让程序报错,主要是为了测试后面的代码是否会继续执行
		console.log(a); 
	}
	
	fn1();
	
	
	function fn2() {
		console.log(888);
	}
	//因为上面的fn1()函数报错了,所以fn2()函数不会再继续执行了
	fn2();
</script>

<script type="text/javascript">
	function fn3() {
		console.log(999); //999
	}
	//尽管上面的fn1()函数报错了,但是fn3()函数还是会继续执行
	fn3();
</script>

<script type="text/javascript">
	function fn4() {
		console.log(123); //123
	}
	
	//尽管上面的fn1()函数报错了,但是fn4()函数还是会继续执行
	fn4();
	
</script>
</html>

猜你喜欢

转载自blog.csdn.net/czh500/article/details/107790622
今日推荐