截取文件后缀名

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
//截取文件后缀名:abcdef.png.jpg ===> jpg;
var a = 'abcdef.png.jpg';
var index = a.lastIndexOf('.');//先找到最后一个.出现的位置;
alert(a.substring(index + 1));//从最后一个.出现的位置开始截取到最后;
// alert(index)
</script>
</head>
<body>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/yxs1530/p/10242405.html