click事件工作正常,但onmouseover事件不起作用.
ProfImage = React.createClass({
getInitialState: function() {
return { showIcons: false };
},
onClick: function() {
if(this.state.showIcons == true) {
this.setState({ showIcons: false });
}
else {
this.setState({ showIcons: true });
}
},
onHover: function() {
this.setState({ showIcons: true });
},
render: function() {
return (
<div>
<span className="major">
<img src="/images/profile-pic.png" height="100" onClick={this.onClick} onmouseover={this.onHover} />
</span>
{ this.state.showIcons ? <SocialIcons /> : null }
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud)
Oce*_*uto 23
你需要把一些字母大写.
<img src="/images/profile-pic.png" height="100" onClick={this.onClick} onMouseOver={this.onHover} />
Run Code Online (Sandbox Code Playgroud)
Min*_*ain 13
上面的答案都是正确的,但你需要将这些方法绑定到类上下文!
<img src="/images/profile-pic.png" height="100" onClick={this.onClick.bind(this)} onMouseOver={this.onHover.bind(this)} />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49607 次 |
| 最近记录: |