我有文件上传输入:
<input onChange={this.getFile} id="fileUpload" type="file" className="upload"/>
我这样处理上传:
getFile(e) {
e.preventDefault();
let reader = new FileReader();
let file = e.target.files[0];
reader.onloadend = (theFile) => {
var data = {
blob: theFile.target.result, name: file.name,
visitorId: this.props.socketio.visitorId
};
console.log(this.props.socketio);
this.props.socketio.emit('file-upload', data);
};
reader.readAsDataURL(file);
}
如果我上传同一文件两次,则不会触发上传事件。我该如何解决这个问题?对于简单的 js 代码,执行以下操作就足够了: this.value = null;在更改处理程序中。我怎样才能用ReactJS做到这一点?
我认为你可以像这样清除输入值:
e.target.value = null;
文件输入无法控制,没有 React 特定的方法可以做到这一点。
Edit对于旧浏览器(以下技术之一.
See http://jsbin.com/zurudemuma/1/edit?js,输出 http://jsbin.com/zurudemuma/1/edit?js,output(在 IE10 和 9 上测试)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)