質問

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