事件绑定处理
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>事件處理</title>
</head>
<body>
<div id="app"></div>
<script src="node_modules/@babel/standalone/babel.js"></script>
<script src="node_modules/react/umd/react.development.js"></script>
<script src="node_modules/react-dom/umd/react-dom.development.js"></script>
<script type="text/babel">function handleClick () {window.alert('hello')}// 1. 使用駝峰命名// 2. 必須綁定一個函數// 3. 不能使用字符串的方式,一定要使用 {函數} 來綁定const element = (<div><button onClick={handleClick}>點我</button>{/* 直接綁定一個匿名函數 */}<button onClick={() => alert('hello world')}>行內處理</button></div>)ReactDOM.render(element, document.getElementById('app'))
</script>
</body>
</html>
?
總結