为什么十六进制代码不显示在reactjs中

时间:2019-12-08 20:17:10

标签: reactjs hex

?和?代码使用纯HTML格式。如何让他们发挥作用?

<!DOCTYPE html>
<html>
  <head>
   <meta charset="UTF-8" />
    <title>Like Click</title>
    <script src="react/react.js"></script>
    <script src="react/react-dom.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

  </head>
  <body>
  <div id='container'>
  </div>

  </body>
  </html>



<script type='text/jsx'>
class Like extends React.Component{
   constructor(props){
      super(props);
      this.state={liked:false};

   }
   toggle(){
      this.setState({liked: !this.state.liked});
   }
   render(){
      var name = this.props.name;
      var txt = this.state.liked ? 'Like':'Unlike';
      var weight = this.state.liked ? 'bold':'normal';
      var color =  this.state.liked ? 'green':'red';
      var thumb =  this.state.liked ? "&#x1F44D;":"&#x1F44E;";
      return(
         <div>
            <span style={{fontWeight:weight,color:color}} onClick={this.toggle.bind(this)}> {name} {thumb}{txt} </span>
         </div>
      );
   }
}
ReactDOM.render(
   <Like name='Java'  />,document.getElementById('container')
);

0 个答案:

没有答案