JavaScript标签的应用

在Java Script支持给代码块定义一个标签(标记某些JS语句),然后应用在break 和 continue 语句中。

语法

labelName:
{statements}

使用break 和 continue 语句跳出标记的代码块。

break labelName;

continue labelName;

代码实例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<script>
cars=["BMW","Volvo","Saab","Ford"];
list:{
	document.write(cars[0] + "
"
); document.write(cars[1] + "
"
); document.write(cars[2] + "
"
); break list; document.write(cars[3] + "
"
); document.write(cars[4] + "
"
); document.write(cars[5] + "
"
); } </script> </body> </html>

你可能感兴趣的:(笔记,JavaScript)