JavaScript Switch 发表于 2016-10-13 | 分类于 前端 | | 阅读次数 1. 直接上代码12345678910111213141516171819202122232425262728293031323334353637383940414243function 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;} 结果123getIconByFormat("doc") => wordgetIconByFormat("wmv") => videogetIconByFormat("jpeg") => image 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏