我想在上传文件时显示文件名。文件名应显示在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());});
我该怎么做?
答案 0 :(得分:0)
使用
$("#filename").html($this.val().split('\\').pop());