react 事件使用

xiaoxiao2022-05-13  8

react中事件都需要使用驼峰命名法(第一个单词后的首个字母为大写)

在js里onclick 都为小写;但在jsx里需要onClick onmouseover ---> onMouseOver <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <script src="./bower_components/react/react.js"></script> <script src="./bower_components/react/react-dom.js"></script> <script src="./bower_components/babel/browser.js"></script> <div id="app"></div> <script type="text/babel"> //如果多标签可以在外面定义 var a = (<div> <div onClick={show}> hellow react !</div> <span>dsfsdf</span> </div>); function show(){ alert(1) } ReactDOM.render( a,//写入内容元素 document.getElementById('app')//插入那个模块 ) </script> </body> </html>

 

 

 

转载请注明原文地址: https://www.6miu.com/read-4884159.html

最新回复(0)