2017-09-12 67 views
-1

我是一個React JS newbe。我有一個非常簡單的代碼,它在應該由onClick觸發的函數中使用alert。但是,事件不會在Chrome(或任何其他瀏覽器)中觸發。我錯過了什麼?我用google搜索了一下,然後玩弄了代碼,但似乎無法弄清楚。React JS事件處理程序沒有響應

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>React - Template</title> 
    <script crossorigin src="https://unpkg.com/[email protected]/dist/react.min.js"></script> 
    <script crossorigin src="https://unpkg.com/[email protected]/dist/react-dom.min.js"></script> 
    <script src="https://unpkg.com/[email protected]/babel.min.js"></script> 
</head> 
<body> 

<div id="container"></div> 

<script type="text/babel"> 

    var Comment = React.createClass({ 

     edit: function() { 
      alert('Editing comment'); 
     }, 
     remove: function() { 
      console.log("Removing"); 
      alert('Removing comment'); 

     }, 
     render: function() { 
      return (
        <div className="commentContainer"> 
         <div className="commentText">{this.props.children}</div> 
         <button onclick={this.edit} className="button-primary">Edit</button> 
         <button onclick={this.remove} className="button-danger">Remove</button> 
        </div> 
      ); 
     } 
    }); 


    ReactDOM.render(
      <div className="board"> 
       <Comment title="Blah">Blah</Comment> 
      </div> 
     , document.getElementById('container')); 

</script> 

</body> 
</html> 

回答

相關問題