//获取文件名称
function getFileName(path) {
    var pos1 = path.lastIndexOf('/');
    var pos2 = path.lastIndexOf('\\');
    var pos = Math.max(pos1, pos2);
    if (pos < 0) {
        return path;
    }
    else {
        return path.substring(pos + 1);
    }
}
 
$(document).ready(function () {
    $('#file').change(function () {
        var str = $(this).val();
        var fileName = getFileName(str);
        var fileExt = str.substring(str.lastIndexOf('.') + 1); 
        alert(fileName + "\r\n" + fileExt);
    });
});

 

posted on 2019-09-27 17:12  夏沫忆香  阅读(2524)  评论(0编辑  收藏  举报