我在一个表格单元格上有一个 onClick (React)处理程序,它可以正确地触发,但是我想保持“在一个新的标签中打开”的特性,在标签上有一个 href
就可以了。
当然,试图将两者结合在一个元素上并不像预期的那样奏效:
<td onClick={this.someFunction} href="someLink">
...some content
<td>
Previously I looked into having an anchor tag nested inside the table cell span the full height, so whenever the contents of the cell were right-clicked, I could "Open in a New Tab" and still keep an onClick
handler on the table cell element. However there's various problems with that approach, 在这里概述.
TLDR: 重写会导致其他问题。解决方案有各种兼容性问题。
因此,我放弃了这种方法,转而采用上面解释的那种方法。有什么想法或建议吗? Is there a way to have the option "Open in a New Tab" without having to use an anchor/href?