문제

I've styled a file input (making the opacity=0) but I would like to display the slected file in a new span. I've copied the input value and pasted it into a span with jquery:

        $('#file').on('change', function () {
            $('#filemask').val($(this).val());
        }).change();

So, I'm getting this value: "C:\fakepath\file.txt". I'm not sure how to trim the first 12 characters from the value so that I'm just left with: "file.txt"

Thanks!

도움이 되었습니까?

해결책

$('#file').on('change', function () {
   var parts = $(this).val().split('\\');
   $('#filemask').val(parts[parts.length -1]);
}).change();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top