javascript if 语句的嵌套用法实例
if语句的嵌套
在JavaScript中,if语句是可以嵌套使用的,大家看看下面一个例子,琢磨一下就知道if语句的嵌套是怎么用了。
举例:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var x=6;
var y=8;
if(x<4)
{
if(y==10)
{
alert("x<4&&y==10");
}
else
{
alert("x<4&&y!=10");
}
}
else if(x>5)
{
if(y==10)
{
alert("x>5&&y==10");
}
else
{
alert("x>5&&y!=10");
}
}
</script>
</head>
<body>
</body>
</html>
在浏览器预览效果如下: