Pregunta

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!

¿Fue útil?

Solución

$('#file').on('change', function () {
   var parts = $(this).val().split('\\');
   $('#filemask').val(parts[parts.length -1]);
}).change();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top