JavaScript Switch

1. 直接上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function getIconByFormat(format) {
var icon = '';
switch (format) {
case 'ppt':
icon = 'ppt';
break;
case 'doc':
case 'docx':
icon = 'word';
break;
case 'mid':
case 'wma':
case 'wav':
case 'flac':
case 'm4a':
case 'voc':
case 'mp3':
icon = 'music';
break;
case 'flv':
case 'avi':
case 'mkv':
case 'wmv':
case 'mp4':
case 'f4v':
case 'mpg':
case 'asf':
case 'webm':
case 'mov':
case 'rmvb':
case 'rm':
case 'mp4':
icon = 'video';
break;
case 'jpg':
case 'jpeg':
icon = 'image';
break;
default:
break;
}
return icon;
}

结果

1
2
3
getIconByFormat("doc") => word
getIconByFormat("wmv") => video
getIconByFormat("jpeg") => image
坚持原创技术分享,您的支持将鼓励我继续创作!