Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使事件停止在React中传播_Javascript_Reactjs_Dom Events - Fatal编程技术网

Javascript 如何使事件停止在React中传播

Javascript 如何使事件停止在React中传播,javascript,reactjs,dom-events,Javascript,Reactjs,Dom Events,首先,我看了所有相关的答案,但没有一个解决了我的问题。我有以下资料: class TweetingBox extends React.Component{ render(){ return ( <div id="page-blackout" onClick={this.props.closeTweetingInterface}> <div id="tweeting-bo

首先,我看了所有相关的答案,但没有一个解决了我的问题。我有以下资料:

class TweetingBox extends React.Component{
    render(){
        return (
            <div id="page-blackout" onClick={this.props.closeTweetingInterface}>
                <div id="tweeting-box" onClick={(proxy) => {proxy.stopPropogation()}}>
                    <h5 id="tweeting-box-header">Compose new Tweet</h5>
                    <TweetingInterface initialContent={this.props.initialContent}/>
                </div>
            </div>
        )
    }
}
类TweetingBox扩展了React.Component{
render(){
返回(
{proxy.stopPropogation()}}>
撰写新推文
)
}
}

带有
id=“page blackout”
的div覆盖整个页面,带有
id=“tweeting box”
的div位于页面中央,在组件
TweetingInterface
中包含一个表单。当我单击表单中的任意位置以及推文框本身时,
this.props.closeTweetingInterface
被调用。如何停止此操作?

所有同级元素都将获得其父属性,因此每次调用父元素或同级元素时,父函数都将被调用为closeTweetingInterface。

可能是
页面黑屏
位于
推文框
的顶部,因此您实际单击了覆盖?否则,您使用的
stopPropogation
方法是正确的,应该会起作用。我认为您的方法是正确的,您只是有一个拼写错误。它应该是
proxy.stopPropagation()
那么我如何在这里得到我想要的结果呢?你可以有一个父元素,在这个父元素中,你可以有同级元素,第一个可以是交叉图标或者你点击的东西,它执行closeTweetingInterface函数,另一个同级元素是tweeting box,它可以有onClick={(proxy)=>{proxy.stopprogation()}}