[英]React onClick event handler not firing ...?
I have a pretty simple div that I need to react when I click it.我有一个非常简单的 div,当我点击它时我需要做出反应。 I minified the problem to below but I can not get a log the Chrome debug screen not matter what I try.
我将问题缩小到下面,但无论我尝试什么,我都无法获取 Chrome 调试屏幕的日志。
I have tried different syntaxes but below is the "simplest" one.我尝试了不同的语法,但下面是“最简单”的语法。 I don't know what else to try but the div will not respond.
我不知道还能尝试什么,但 div 不会响应。
constructor(props) {
super(props);
this.divClicked = this.divClicked.bind(this);
}
divClicked (e) {
console.log("DEBUG: divClicked!");
}
render () {
const data = this.props.data;
return (
<div onClick={this.divClicked} id={data.id + 'a'} className='url1_div'>
</div>
);
}
}
divClicked never fires and this is such a simple example I'm wondering is a parent component is causing the issue or some other component is some how effecting it. divClicked 永远不会触发,这是一个如此简单的示例,我想知道是父组件导致了问题还是某些其他组件对其产生了影响。
I have replicated your code on StackBlitz , and it works.我已经在StackBlitz上复制了您的代码,并且可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.