使用javascript显示文件名上传

时间:2016-05-01 03:54:17

标签: javascript upload filenames

我想在上传文件时显示文件名。文件名应显示在span id =“filename”

<p>
    <label style="width: 30%">Image</label>
    <label class="custom-file-upload" style="width: 23%"> 
        <input type="file" name="img_1" id="img_1"/> <i class="fa fa-cloud-upload"></i> Image 1
    </label>
    <span id="filename">none selected...</span> 
</p>

如果我使用这个js代码,文件名将显示在标签

$("input[id='img_1']").change(function (e) {
var $this = $(this);
$this.next().html($this.val().split('\\').pop());});

我该怎么做?

1 个答案:

答案 0 :(得分:0)

使用

$("#filename").html($this.val().split('\\').pop());