2016-03-01 38 views
7

click事件工作正常,但onmouseover事件不起作用。onmouseover不能與React.js一起使用

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> 

     ); 
    } 

}); 

回答

10

您需要將一些字母大寫。

<img src="/images/profile-pic.png" height="100" onClick={this.onClick} onMouseOver={this.onHover} /> 
11

上述兩個答案都是正確的,但是您還需要將這些方法綁定到類上下文!

<img src="/images/profile-pic.png" height="100" onClick={this.onClick.bind(this)} onMouseOver={this.onHover.bind(this)} /> 
+1

'onMouseOver = {this.onHover.bind(this,'value')}'' –

相關問題