简体   繁体   English

jQuery不会在第一次点击时触发,但会在第二次点击时触发

[英]jQuery doesn't fire on first click but does on second

$(document).ready(function() {
    $('#talents li').on('click',  'div', function(event) {
        event.stopPropagation();

        $(event.target).addClass('--active');
        talents_points = $('.--active').length;
        _this.setState({ points: talents_points });
        this.handlePointsMaxed(talents_points);
    });
    $('.no-right-click').bind('contextmenu', function(event) {
        event.stopPropagation();

        $(event.target).removeClass('--active');
        talents_points = $('.--active').length;
        _this.setState({ points: talents_points });
        // this.handlePointsMaxed(talents_points);

        return false;
    });
});

<ul id="talents">
    <li onClick={this.handlePointsClicks}>
        <div id="talent-stacks" className="talent-image__stacks"></div>
    </li>
</ul>`

Any idea why? 知道为什么吗? I'm positive it's on the mousedown and click functions but I need them both for what I making and have not found another way to combine these. 我很肯定它是在mousedown和点击功能,但我需要它们为我所做的,并没有找到另一种方式来结合这些。

EDIT: Added the HTML sample for context 编辑:添加了上下文的HTML示例

I was able to fix this, I didn't have the function set correctly in the componentDidMount lifecycle of the react component. 我能够解决这个问题,我没有在react组件的componentDidMount生命周期中正确设置该函数。

Thanks everyone for your input. 谢谢各位的意见。

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

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