-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path6state.html
47 lines (42 loc) · 939 Bytes
/
6state.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
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React 6_State</title>
<script src="JSXTransformer.js"></script>
<script src="react.min.js"></script>
</head>
<body>
<script type="text/jsx">
/**
* @jsx React.DOM
*/
var StateDemo = React.createClass({
// 这个方法用来初始化状态
getInitialState: function() {
return {
clicks: 0
}
},
// 这里是事件
onBtnClick: function() {
this.setState({
clicks: this.state.clicks + 1
})
},
render: function() {
return (
<div>
<div>点击数:<strong>{this.state.clicks}</strong></div>
<button onClick={this.onBtnClick}>点我增加点击数</button>
</div>
)
}
});
React.render(
<StateDemo />,
document.body
);
</script>
</body>
</html>