5.jsx_样式绑定.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./babel.min.js"></script>
  8. <script src="./react.development.js"></script>
  9. <script src="./react-dom.development.js"></script>
  10. </head>
  11. <body>
  12. <div id="root"></div>
  13. <script type="text/babel">
  14. const headStyle = {
  15. // 小驼峰命名法
  16. color: 'red',
  17. fontSize: '17px',
  18. backgroundColor: '#ff0'
  19. }
  20. const isActive = false;
  21. const activestyle = {
  22. color: 'green'
  23. }
  24. const nostyle = {
  25. color: 'blue'
  26. }
  27. const element = (
  28. <div>
  29. <h1 style={headStyle}>Style样式绑定</h1>
  30. <h3 style={{ color: 'plum' }}>哈哈哈</h3>
  31. <span style={isActive ? activestyle : nostyle}>{isActive ? '已激活' : '未激活'}</span>
  32. </div>
  33. )
  34. const container = document.getElementById("root");
  35. const root = ReactDOM.createRoot(container)
  36. root.render(element);
  37. </script>
  38. </body>
  39. </html>