-
Notifications
You must be signed in to change notification settings - Fork 4
/
7page.html
105 lines (97 loc) · 2.38 KB
/
7page.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React 7_Page</title>
<script src="JSXTransformer.js"></script>
<script src="react.min.js"></script>
</head>
<body>
<script type="text/jsx">
/**
* @jsx React.DOM
*/
// 文章组件-标题
var ArticleTitle = React.createClass({
render: function () {
return (
<hgroup>
<h1>{this.props.title}</h1>
<h2>{this.props.subtitle}</h2>
</hgroup>
)
}
});
// 文章组件-内容
var ArticleContent = React.createClass({
render: function () {
return (
<main>{this.props.content}</main>
)
}
});
// 文章组件-落款
var ArticleFooter = React.createClass({
render: function () {
return (
<footer>
<div class="author">{this.props.author}</div>
<div class="datetime">{this.props.publishtime}</div>
</footer>
)
}
});
// 文章组件-已读按钮
var ArticleIsRead = React.createClass({
// 这个方法用来初始化状态
getInitialState: function() {
return {
isread: false
}
},
// 按钮点击事件
onreadit : function () {
this.setState({
//isread : true
isread : !this.state.isread
});
},
render: function () {
var text = this.state.isread ? '已读' : '未读';
return (
<button onClick={this.onreadit}>
{text}
</button>
)
}
});
// 文章组件,组合上述Title+Content+Footer+IsRead4个组件
var Article = React.createClass({
render: function () {
return (
<div>
<ArticleTitle
title = {this.props.title}
subtitle = {this.props.subtitle}
//title = "大标题"
//subtitle = "小标题"
/>
<ArticleContent
content = "文章内容啊!"
/>
<ArticleFooter
author = "作者"
publishtime = "发布时间"
/>
<ArticleIsRead />
</div>
)
}
});
React.render(
<Article title="大大标题" subtitle="大小标题"/>,
document.body
);
</script>
</body>
</html>