我想阻止点击事件起泡。因此,我在代码中添加了e.stopPropagation()。我总是在控制台中看到一个错误,那就是:Uncaught TypeError: e.stopPropagation is not a function
Uncaught TypeError: e.stopPropagation is not a function
在reactjs中设置stopPropagation的正确方法是什么?
handleClick: function(index, e) { e.stopPropagation(); ... },
正确的方法是使用.stopPropagation,
.stopPropagation
var Component = React.createClass({ handleParentClick: function() { console.log('handleParentClick'); }, handleChildClick: function(e) { e.stopPropagation(); console.log('handleChildClick'); }, render: function() { return <div onClick={this.handleParentClick}> <p onClick={this.handleChildClick}>Child</p> </div>; } });
Example
您的事件处理程序将传递SyntheticEvent实例,该实例是围绕浏览器本地事件的跨浏览器包装器。它具有与浏览器本机事件相同的接口,包括stopPropagation()和preventDefault(),不同之处在于这些事件在所有浏览器中均相同。 Event System
Event System