1.流程控制语句
- 条件判断语句:if...else
- 条件分支语句:switch..case
- 循环语句:for while do...while
0.1条件判断语句
<style type="text/css">
.box{
width: 300px;
height: 300px;
background-color: palevioletred;
}
</style>
<script type="text/javascript">
window.onload = function () {
var btn = document.getElementById("btn");
var box = document.getElementById("box");
btn.onclick = function () {
if(box.style.display == "none"){
box.style.display = "block";
}else {
box.style.display = "none";
}
}
}
</script>
</head>
<body>
<input type="button" value="切换" id="btn">
<br/>
<div class="box" id="box"></div>
</body>
0.2多重条件判断语句
switch case如果不使用break会穿透 也就是依次往下执行
<script type="text/javascript">
var today = 4;
/*if(today == 1){
alert("语文");
}else if(today == 2){
alter("数学");
}else if (today == 3){
alert("英语");
}else if(today == 4){
alert("美术");
}else if(today == 5){
alert("舞蹈");
}else {
alert("不补习");
}*/
switch (today) {
case 1:
alert("语文");
break;
case 2:
alert("数学")
break;
case 3:
alert("英语")
break;
case 4:
alert("美术")
break;
case 5:
alert("舞蹈")
break;
default:
alert("不补习")
}
</script>