一、JavaScript条件语句
1.if...else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-8"
>
<title>Title</title>
</head>
<body>
<script>
var
i=11;
if
(i==10){
document.write(
"yeleven"
);
}
else
{
document.write(
"yeleven2"
);
}
</script>
</body>
</html>
|
2.switch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-8"
>
<title>Title</title>
</head>
<body>
<script>
var
i=5;
switch
(i){
case
1:
document.write(
"i=1"
);
break
;
case
2:
document.write(
"i=2"
);
break
;
default
:
document.write(
"条件不满足case"
);
break
;
}
</script>
</body>
</html>
|
本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1791880