【问题标题】:Material-UI File Upload with ButtonMaterial-UI 文件上传按钮
【发布时间】:2021-01-01 13:21:44
【问题描述】:

我正在尝试通过单击按钮进行文件上传,但是存在一些问题。

                  <label>
                        <input
                        style={{ display: 'none' }}
                        type="file"
                        />     
                        <Button variant="contained" color="default">Upload</Button>
                    </label>

这是我的代码,但单击按钮时文件上传不起作用,因此未检测到输入。我该如何解决?

我正在使用 React 和 Material-UI。

【问题讨论】:

标签: reactjs material-ui


【解决方案1】:

您可能会错过输入的 id:

让我们试试:

  <input
    style={{ display: "none" }}
    id="contained-button-file"
    type="file"
  />
  <label htmlFor="contained-button-file">
    <Button variant="contained" color="primary" component="span">
      Upload
    </Button>
  </label>
</div>

【讨论】:

  • 我试过了,但不会显示文件名。这是预期的行为吗?
猜你喜欢
  • 2019-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-05
  • 1970-01-01
  • 2019-07-24
相关资源
最近更新 更多