书法字典:https://www.shufadict.com

html file input onchage没有调用(两次选择同一个文件)

在html中,如果input的类型是file,且第二次选择的文件与第一次相同,那么onchange事件不会调用。

如果想调用,需要将event.target.value设置为null,如下:

原生写法:

<input id="file" onchange="file_changed(this)" onclick="this.value=null;" type="file" accept="*/*" />

React写法:

 <input className="input_tag" type="file" accept="image/*" onChange={onImageSelect}/>
const onImageSelect = (event: any) => {
    const files = event.target.files;
    event.target.value = '';
};

= The End =

posted on 2020-07-09 14:42  翰墨小生  阅读(872)  评论(0编辑  收藏  举报

导航

书法字典:https://www.shufadict.com