您也可以这样做。同时拥有onClick和onContextMenu处理程序
return <p onClick={this.handleClick} onContextMenu={this.handleClick}>Something </p>
您可以
nativeEvent根据其他答案的建议进行检查,也可以进行检查
type。(此外,如果右键单击,请阻止默认设置。)
使用
type
handleClick: function(e) { if (e.type === 'click') { console.log('Left click'); } else if (e.type === 'contextmenu') { console.log('Right click'); }}
使用
nativeEvent
handleClick: function(e) { if (e.nativeEvent.which === 1) { console.log('Left click'); } else if (e.nativeEvent.which === 3) { console.log('Right click'); }}
这是一个演示
http://jsbin.com/seyeliv/edit?html,输出
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)