简体   繁体   English

动态生成的按钮未单击React

[英]Dynamically-generated Button not clicking React

I am using a button in my react component and it's onClick callback is never triggering. 我在我的react组件中使用了一个按钮,它的onClick回调从未触发。 The component is generated based on data in a .map function and it looks and behaves correctly other than the button. 该组件是根据.map函数中的数据生成的,除了按钮之外,它的外观和行为均正确。 I have two buttons (flagged in code), neither of which work. 我有两个按钮(在代码中标记),两个按钮都不起作用。 Here is the code: 这是代码:

var namesList = this.state.data.map(function(name, index){
                return (
                  <div>
                        <a class="btn" onCLick={() => alert('alert')} style={{width: '70%', marginTop: '33px'}}>
                          <span>click</span>
                        </a>
                        <button onCLick={() => alert('alert')} > button </button>
                  </div>
                );
              })

Why is this the case? 为什么会这样呢?

I see a typo here: 我在这里看到一个错字:

onCLick={() => alert(‘alert’)}

Should be: 应该:

onClick={() => alert('alert')}

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

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