Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应:输入onChange-won';不要第二次开火,第一次开火';工作_Javascript_Html_Reactjs - Fatal编程技术网

Javascript 反应:输入onChange-won';不要第二次开火,第一次开火';工作

Javascript 反应:输入onChange-won';不要第二次开火,第一次开火';工作,javascript,html,reactjs,Javascript,Html,Reactjs,最近我编写了React JS应用程序,从外部导入图像并处理该图像。为了处理用户onChange事件,我使用onChange运行我的函数handleChange,但是第二次它不会工作。如何正确处理onChange事件? 这是我的密码 <div className={classes.fileUpload}> <div style={{ position: "relativ

最近我编写了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>

handleChange(e.target.files)}
/>
上传文件
试试这个

import React from 'react'

class SimpleReactFileUpload extends React.Component {

  constructor(props) {
    super(props);
    this.state ={
      file:null
    }
  
    this.onChange = this.onChange.bind(this)
  }

  onChange(e) {
    this.setState({file:e.target.files[0]})
  }


  render() {
    return (
      <form onSubmit={this.onFormSubmit}>
        <h1>File Upload</h1>
        <input type="file" onChange={this.onChange} />
        
      </form>
   )
  }
}



export default SimpleReactFileUpload
从“React”导入React
类SimpleReactFileUpload扩展了React.Component{
建造师(道具){
超级(道具);
这个州={
文件:空
}
this.onChange=this.onChange.bind(this)
}
onChange(e){
this.setState({file:e.target.files[0]})
}
render(){
返回(
文件上传
)
}
}
导出默认的SimpleReactFileUpload
希望它能起作用

试试这个

import React from 'react'

class SimpleReactFileUpload extends React.Component {

  constructor(props) {
    super(props);
    this.state ={
      file:null
    }
  
    this.onChange = this.onChange.bind(this)
  }

  onChange(e) {
    this.setState({file:e.target.files[0]})
  }


  render() {
    return (
      <form onSubmit={this.onFormSubmit}>
        <h1>File Upload</h1>
        <input type="file" onChange={this.onChange} />
        
      </form>
   )
  }
}



export default SimpleReactFileUpload
从“React”导入React
类SimpleReactFileUpload扩展了React.Component{
建造师(道具){
超级(道具);
这个州={
文件:空
}
this.onChange=this.onChange.bind(this)
}
onChange(e){
this.setState({file:e.target.files[0]})
}
render(){
返回(
文件上传
)
}
}
导出默认的SimpleReactFileUpload

希望它能起作用

你第二次选择的是同一个文件吗?你试过输入吗?谢谢,输入它的工作吗?你第二次选择的是同一个文件吗?你试过输入吗?谢谢,输入它的工作这样做很复杂。我试过输入和它的工作,谢谢你用这种复杂的方式来做。我试过输入和它的工作,谢谢你