【发布时间】:2020-10-26 12:45:36
【问题描述】:
有一个输入表单(文件类型):
<input
name="image"
id="image-input"
accept="image/*"
onChange={this.uploadFile}
multiple
type="file"
className="imgInp"
/>
如何在上面添加文字?我不希望它出现在输入之外,在这种情况下,我会添加一个跨度,例如:<span> Upload image </span> 但我希望文本出现在输入中。
在this page 上,它表示必须添加一个属性value,但如果我将其添加到输入中,则会引发此错误:
InvalidStateError: Failed to set the 'value' property on'HTMLInputElement': This input element accepts a filename, which mayonly be programmatically set to the empty string.
<input
name="image"
id="image-input"
accept="image/*"
onChange={this.uploadFile}
multiple
type="file"
className="imgInp"
value="Upload image" //this is where value was added
/>
有没有办法让它工作?
【问题讨论】:
-
看来您使用的是框架,对吧?是哪个?
-
我正在使用 React
标签: javascript html reactjs input