-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path点击按钮增加数量.html
41 lines (41 loc) · 1.42 KB
/
点击按钮增加数量.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!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>
<div id="root"></div>
<script src="https://cdn.bootcss.com/react/15.6.1/react.min.js"></script>
<script src="https://cdn.bootcss.com/react/15.6.1/react-dom.min.js"></script>
<script src="https://cdn.bootcss.com/babel-standalone/7.0.0-alpha.15/babel.min.js"></script>
<script type="text/babel">
var ButtonCount = React.createClass({
getInitialState: function(){
return {
clickCount: 0 //设置h1点击数量初始值
}
},
buttonClick: function(){
this.setState({
clickCount: this.state.clickCount +1 //出发按钮点击事件后clickCount的值+1
});
},
render: function(){
return (
<div>
<button onClick={this.buttonClick}>点击</button>
<h1>点击数量:{this.state.clickCount}</h1>
</div>
);
}
});
ReactDOM.render(
<ButtonCount/>,
document.getElementById('root')
);
</script>
</body>
</html>