0
import React, { Component } from 'react'
class Example extends React.Component {
constructor(props){
super(props)
this.handleWinner = this.handleWinner.bind(this);
}
handleWinner(event){
event.preventDefault();
alert("Buttet Pressed")
}
render() {
return (
<td key=1><button onClick={this.handleWinner}>Click Me</button></td>
)
}
我的功能不是对调度按钮单击按钮单击事件不工作ReactJS
尝试同样的代码在[沙盒(https://codesandbox.io/s/7L6l1mRy)。似乎工作。请检查你是否缺少一些东西。 –
不能有'key = 1' - 应该是'key = {1}'或'key =“1”' - 否则jsx解析器会抛出。但是,是的,它的工作原理 - https://codepen.io/anon/pen/gxRavE –