简体   繁体   English

onmouseover没有使用React.js

[英]onmouseover not working with React.js

The click event works fine, but the onmouseover event does not work. 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>

        );
    }

});

你需要把一些字母大写。

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

上面的答案都是正确的,但你需要将这些方法绑定到类上下文!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM