-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
133 lines (106 loc) · 2.83 KB
/
main.js
File metadata and controls
133 lines (106 loc) · 2.83 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React from 'react';
import ReactDOM from 'react-dom';
import App from './app.jsx';
/*ReactDOM.render(
<App/>, //App 必须和模版抛出的名字一样
document.getElementById('app')
);*/
/*ReactDOM.render(
<h1>Hellow World!</h1>,
document.getElementById('example')
);*/
/*ReactDOM.render(
<div>
<h1>菜鸟教程</h1>
<h2>欢迎学习React</h2>
<p>这是一个很不错的 Javasript 库!</p>
</div>,
document.getElementById('example')
);
*/
/*
var i=1;
ReactDOM.render(
//<h1>{1+1}</h1>,
<h1>{i=1?'True!':'False'}</h1>,
document.getElementById('example3')
);*/
/*
var myStyle={
fontSize:100,
color:'#ff0000'
};
ReactDOM.render(
<h1 style={myStyle}>洋码头</h1>,
document.getElementById('example3')
);*/
/* var arr=[<h1>我</h1>,<h2>学的不是技术,是梦想!</h2>]
ReactDOM.render(
<p>{arr}</p>,
document.getElementById('example3')
);*/
/* var $div=<div className="foo"/>
ReactDOM.render(
$div,
document.getElementById('example3')
);
*/
//渲染react组件(组件名开始字母为大写)
/*ar HelloMessage=React.createClass({
render:function(){
return <h1>hi {this.props.name}</h1>;
}
});
ReactDOM.render(
<HelloMessage name="洋码头"/>,
document.getElementById('example3')
);*/
/* var WebSite=React.createClass({
render:function(){
return(<div>
<Name name={this.props.name}/>
<Link site={this.props.site}/>
</div>
);
}
});
var Name=React.createClass({
render:function(){
return(
<h1>{this.props.name}</h1>
);
}
});
var Link=React.createClass({
render:function(){
return(
<a href={this.props.site}>
{this.props.site}
</a>
);
}
});
ReactDOM.render(
<WebSite name="fdb" site="http://www.runoob.com"/>,
document.getElementById('example3')
);*/
var LikeButton=React.createClass({
getInitialState:function(){
return {liked:false};
},
handleClick:function(){
this.setState({liked:!this.state.liked});
},
render:function(){
var text=this.state.liked?'喜欢':'不喜欢';
return (
<p onClick={this.handleClick}>
你<b>{text}</b>我。点我切换状态。
</p>
);
}
})
ReactDOM.render(
<LikeButton/>,
document.getElementById('example3')
)