11.事件.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // function han
  37. const handleJump = (event) => {
  38. console.log("da'yin")
  39. event.preventDefault();
  40. }
  41. function WelCome() {
  42. return (
  43. <div>
  44. <h1 onClick={handleClick}>欢迎光临</h1>
  45. <h1 onClick={() => console.log('哈哈')}>欢迎光临2</h1>
  46. <div className='box1' onClick={handleBox1}>
  47. <div className='box2' onClick={handleBox2}>
  48. </div>
  49. </div>
  50. <a href="http://www.baidu.com" onClick={handleJump}>跳转</a>
  51. </div>
  52. )
  53. }
  54. const element = <WelCome />
  55. const container = document.getElementById("root");
  56. const root = ReactDOM.createRoot(container)
  57. root.render(element);
  58. </script>
  59. </body>
  60. </html>