直接上代码
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;
}
结果:
getIconByFormat("doc") => word
getIconByFormat("wmv") => video
getIconByFormat("jpeg") => image