-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-8.html
More file actions
72 lines (68 loc) · 2.16 KB
/
react-8.html
File metadata and controls
72 lines (68 loc) · 2.16 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html>
<head>
<title>react-表单与事件</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="app"></div>
</body>
</html>
<script src="./js/react.js"></script>
<script src="./js/react-dom.js"></script>
<script src="http://cdn.bootcss.com/babel-core/5.8.38/browser.min.js"></script>
<script type="text/babel">
// var HelloMsg = React.createClass({
// getInitialState:function(){
// return {
// value:'Hello World'
// };
// },
// handleChange:function(event){
// this.setState({value:event.target.value});
// },
// render:function(){
// var value = this.state.value;
// return <div>
// <input type='text' value={value} onChange={this.handleChange}/>
// <h3>{value}</h3>
// </div>
// }
// });
// ReactDOM.render(
// <HelloMsg/>,
// document.getElementById('app')
// )
//子组件上使用表单
//在父组件创建handleChange,作为prop{updateStateProp}传递到子组件
var Content = React.createClass({
render:function(){
return <div>
<input type='text' value={this.props.propData} onChange={this.props.updataStateProp} />
<h3>{this.props.propData}</h3>
</div>;
}
});
var HelloMsg = React.createClass({
getInitialState:function(){
return {
value:'hello react'
};
},
handleChange:function(event){
this.setState({value:event.target.value});
},
render:function(){
var value = this.state.value;
return <div>
<Content propData = {value} updataStateProp = {this.handleChange}></Content>
</div>;
}
});
ReactDOM.render(
<HelloMsg/>,
document.getElementById('app')
)
</script>