2
如何在上传文件时停止打开文件上载窗口?e.preventDefault()或返回false无法停止文件输入以打开
export default class Upload extends Component {
constructor(props) {
super(props);
this.state = {
filename: null,
isLoading: false
}
}
trigger_upload_input =() => {
document.getElementById("browse-file").click();
}
handleOnChange = (e) => {
if(e.target.files[0]) {
this.setState({filename: e.target.files[0].name, isLoading: true});
var that = this;
setTimeout(function(){
that.setState({isLoading: false})
},3000)
}
}
handleInputClicked = (e) => {
if(this.state.isLoading){
e.preventDefault();
}
}
render() {
const { isLoading } = this.state;
return(
<div className="upload">
<div>
<input onClick={this.handleInputClicked} onChange={this.handleOnChange} type="file" id="browse-file"/>
{this.state.filename && <span>{this.state.filename}</span>}
</div>
</div>
)
}
}
负载指示工作,但是当我尝试点击再次输入e.preventDefault()不停止文件窗口中打开,试图return false
它并没有解决这个问题?
相同,不起作用。 –
可能只是为输入添加一个“disabled”属性以防止它被点击? – ghostprgmr