我有一个文件选择器,当点击按钮时,文件选择器会出现:
<input id='example' type="file" accept="image/*" onChange={this.onImageChange} />
现在我想使用另一个按钮来触发上面的输入框:
<button onClick={() => {
var element = document.getElementById('example');
console.log(element) // This shows <input id="example" type="file" accept="image/*">
// element.onChange() // Error: onChange() is not a function
// Above doesn't work, so I try to trigger the onChange event manually,
// but below doesn't do anything
var event = new Event('change');
element.dispatchEvent(event);
}}></button>