11.事件.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. <style>
  11. .box1 {
  12. width: 400px;
  13. height: 400px;
  14. background: #f00;
  15. }
  16. .box2 {
  17. width: 200px;
  18. height: 200px;
  19. background: #ff0;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="root"></div>
  25. <script type="text/babel">
  26. const handleClick = () => {
  27. console.log("你好")
  28. }
  29. const handleBox1 = () => {
  30. console.log("1111")
  31. }
  32. const handleBox2 = (event) => {
  33. console.log("222")
  34. // event.stopPropagation();
  35. }
  36. const handleJump = (event) => {
  37. console.log("da'yin")
  38. event.preventDefault();
  39. }
  40. function WelCome() {
  41. return (
  42. <div>
  43. <h1 onClick={handleClick}>欢迎光临</h1>
  44. <h1 onClick={() => console.log('哈哈')}>欢迎光临2</h1>
  45. <div className='box1' onClick={handleBox1}>
  46. <div className='box2' onClick={handleBox2}>
  47. </div>
  48. </div>
  49. <a href="http://www.baidu.com" onClick={handleJump}>跳转</a>
  50. </div>
  51. )
  52. }
  53. const element = <WelCome />
  54. const container = document.getElementById("root");
  55. const root = ReactDOM.createRoot(container)
  56. root.render(element);
  57. </script>
  58. </body>
  59. </html>