【发布时间】:2020-07-28 04:35:35
【问题描述】:
最近我编写了我的 React JS 应用程序来从外部导入图像并处理该图像。为了处理用户onChange事件,我使用onChange来运行我的函数handleChange,但是第二次就不行了。如何正确处理onChange 事件?
这是我的代码
<div className={classes.fileUpload}>
<div
style={{
position: "relative",
display: "inline-block",
height: "100%",
width: "100%",
}}
>
<input
type={"file"}
id="file"
accept={"image/png, image/jpeg"}
style={{ display: "none" }}
onChange={(e) => handleChange(e.target.files)}
/>
<label htmlFor="file" className={classes.labelFile}>
<PublishIcon style={{ marginRight: "10px" }} />
Upload file
</label>
</div>
</div>
【问题讨论】:
-
第二次选择同一个文件吗?
-
你试过onInput吗?
-
谢谢,onInput它的工作
标签: javascript html reactjs