1

method one:

 <input type="file" onChange="change(event)">
<script>
function change(event) {
    var fileName = event.target.files[0].name.toLowerCase();
    var lastIndex = fileName.lastIndexOf('.');
    var suffix = fileName.substring(lastIndex, fileName.length);
    console.log(suffix);
}
</script>

Method Two:

 <input type="file" onChange="change(event)">
<script>
function change(event) {
    var fileName = event.target.files[0].name.toLowerCase();
    var suffix = fileName.split('.').pop();
    console.log(suffix);
}
</script>

Method three:

 <input type="file" onChange="change(event)">
<script>
function change(event) {
    var fileName = event.target.files[0].name.toLowerCase();
    var suffix = fileName.match(/.[^.]+$/)[0];
    console.log(suffix);
}

墨城
1.7k 声望2.1k 粉丝