【发布时间】:2019-03-25 17:11:34
【问题描述】:
我有一个按钮,点击后消失。同样单击按钮一次不会导致任何按钮操作运行。我必须单击按钮,然后在按钮消失后单击按钮所在的区域才能使按钮操作生效。
<Grid className={classes.container} style={{justifyContent: 'flex-end'}} item xs={12}>
<Button className={classes.addImage} onClick={this.addPic}>
<input
className={classes.takePic}
ref="file"
id="takePic"
type="file"
accept="image/*"
onChange={this.onChange}
/>
Add
<br></br>
Image
</Button>
</Grid>
样式:
addImage: {
display: 'flex',
backgroundColor: 'black',
color: 'white',
borderRadius: 90,
height: 100,
width: 100,
justifySelf: 'flex-end',
marginRight: '12.5%',
},
onChange函数:
onChange = () => {
let newfile = this.refs.file.files[0];
let reader = new FileReader();
let url = reader.readAsDataURL(newfile);
reader.onloadend = () => {
this.setState({
...this.state,
openModal: true,
imgSrc : [reader.result],
imageType: newfile.type,
newfile: newfile,
filename: `${this.props.user.id}_${Date.now()}`
})
console.log(newfile)
console.log(this.state)
}
}
addPic函数:
addPic = () => {
document.getElementById('takePic').click()
}
【问题讨论】:
-
this.addPic和this.onChange是做什么的?我们可以看到功能吗?还是小提琴? -
我编辑了我的帖子以包含这些功能。我没有将它们包含在原始帖子中,因为这个问题是在我创建这些函数之前发生的。
-
按钮标签内的输入标签??
-
@G_S 既然你提到了它,输入不需要在按钮上。我会尝试移动它,看看是否能解决问题。
-
@tdammon 尝试您的链接时,该按钮不会消失。然而,有一个非常极端的悬停效果,使按钮非常轻。在移动设备上,有时第一次触摸会触发“悬停”(例如工具提示),然后第二次触摸会注册为单击,但我认为 Material-UI 按钮默认情况下不会以这种方式工作,我不能重现您描述的行为 - 我的第一次点击工作正常。
标签: javascript css reactjs material-ui