按钮单击事件不工作ReactJS

时间:2017-08-10 10:35:57

标签: reactjs

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>
       )
}

我的功能是Not Dispatching on Button Click

2 个答案:

答案 0 :(得分:0)

您的render功能缺少}

render() {
  return(
    <td key=1><button onClick={this.handleWinner}>Click Me</button></td>
  )
}

答案 1 :(得分:0)

您尚未正确关闭括号

class Example extends React.Component {
    constructor(props) {
      super(props);
      this.handleWinner = this.handleWinner.bind(this);
    }

    handleWinner(event) {
      event.preventDefault();
      alert("Buttet Pressed")
    }

    render() {
      return <div key=1>
        <button onClick={this.handleWinner}>Click Me</button>
      </div>
    }
}

ReactDOM.render(<Example />, document.getElementById('app'))