input file onchange事件不触发(第二次上传同名文件)/文件上传也可参考

首先, inputonchange事件,inputvalue值改变, 才会触发. 第一次上传a文件, 会触发, 第二次上传该文件, 对于该inputvalue来说, 还是同一个值, 则不触发.
找到js代码中注意1的地方, 那一行, 重置了inputvalue值. 第一次上传完以后, 无论成功还是失败, 这个input的值都是空, 因此, 再次上传同一文件的时候, 又会触发onchange事件. 完美~

html

<div class="input-box">
   <input type="file" name="feature" id="feature" accept="text/plain" @change="uploadPic1(this)">
   <button type="button"  class="btn btn-white m-l-sm float-left m-r-lg">文件上传(txt)</button>
 </div>

css

.input-box {
  display: inline-block;
  position: relative;
}

.input-box>input {
  width: 100%;
  height: 100%;
  padding-left: 10px;
  position: absolute;
  left: 0;
  opacity: 0;
}
//上传文件
    uploadPic1: function (el) { 
	var _this = this;

	// 获取file对象的数据
	var inputFiles = document.querySelector('#feature').files;
	console.log(inputFiles);

	if (inputFiles[0]) {
		var data = {
			file: inputFiles[0]
		};
		// console.log(data);

		request.txtUploadFile(data, function (res) {
			console.log('rrr', res)
			if (res.success) {
				_this.getBatchWithholdList();
				parent.layer.msg('上传成功', {
					icon: 1
				});
			} else {
				parent.layer.msg(res.resultMessage, {
					icon: 2
				})
			}
			$('#feature').val('') // 注意1
			
		});
	} else {
		parent.layer.msg('请选择文件', {
			icon: 2
		})
	}
			

},
  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值