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