简体   繁体   English

onClick 事件监听器不工作不知道为什么

[英]onClick event listener is not working don't know why

I've been trying to log my event object value in 'option' tag and it does not work, but it does work in select tag, here is my code:我一直在尝试在“选项”标签中记录我的事件 object 值,但它不起作用,但它在 select 标签中起作用,这是我的代码:

{data.map((item, index) => {
      const {name, options} = item;
          return (
              <div className="item" key={name}>
                  <label htmlFor={name}>
                      Select any {name}:
                      <select name={name} id={name} onClick={(e) => console.log(e.target.value)}>
                          <option disabled selected>Any {name}</option>
                          {options.map((item, index) => {
                              return (
                                  <option 
                                      value={item} 
                                      key={index} 
                                      onClick={(e) => console.log(e.target.value)}
                                  >{item}</option>
                              )
                          })}
                      </select>
                  </label>
              </div>
          )
      })}

what's wrong with my option tag?我的选项标签有什么问题?

I don't think there is anything wrong with your option tag.我认为您的选项标签没有任何问题。 Did you encounter this issue in Chrome?你在 Chrome 中遇到过这个问题吗?

This seems to be a known issue in Chrome: The onclick event does not work for options这似乎是 Chrome 中的一个已知问题: onclick 事件不适用于选项

Indeed, I tried onClick with both Chrome and Firefox - for the option tag, onClick does fire in Firefox but not in Chrome.确实,我尝试了 onClick 与 Chrome 和 Firefox - 对于选项标签,onClick 确实在 Z763F746Z38D 中触发,但在 Chrome 中不触发。

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

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