我想让我的主div的"display:'none'"按下按钮后。但是它返回了一个错误,似乎声明getElementByID字段为空。
下面是我正在使用的代码片段:
<div className="content" style={Style}>
<ButtonGroup variant="contained" color="primary" size="large">
<Button onClick={() => {this.loadtrainingresources()}}>TRAINING RESOURCES</Button>
</ButtonGroup>
</div>
loadtrainingresources = () =>{
document.getElementById("content").display = "none";
}
错误输出
你忘了style
document.getElementById("content").style.display = "none";
https://www.w3schools.com/jsref/prop_style_display.asp