-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathveiwBlog.html
More file actions
203 lines (182 loc) · 6.26 KB
/
veiwBlog.html
File metadata and controls
203 lines (182 loc) · 6.26 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>veiw the blog</title>
<style type="text/css">
* { margin: 0; padding: 0 }
body { font: 14px "微软雅黑", Arial, Helvetica, sans-serif; background: url('亚马逊中国 z.cn,一站放心购全球_files/cloud2.jpg') no-repeat #075498;background-size: 100% 100%; color: #fff }
img { border: 0; display: block }
header, article { width: 600px; margin: auto; overflow: hidden;font-size: larger;}
.head{ margin-bottom: 40px}
#the-all{overflow:hidden;text-overflow:ellipsis;white-space:pre;padding:3%;width: 700px;height: auto;background-color: white;color: black;}
input{ margin-top:50px;box-shadow: none; outline: none; width: 20%; height: 50%; border-radius: 10px; background-color: white; color: #9f0f17; font-weight: bold; font-size: larger; }
#comment{margin-top:50px;width: 600px;height: 100px;background-color: white;color: black;}
input:hover{cursor: pointer}
#myComment{width: 600px; margin-top: 50px;font-size: larger; }
</style>
</head>
<body>
<header id="top" class="head">
<label>文章标题:</label>
<span id="title" ></span>
</header>
<article id="content">
<label >文章内容:<br>
<div id="the-all"></div>
</label>
<label id="dis">评论:
<!--<div id="comment">comment</div>-->
<!--<div id="comment">comment</div>-->
<!--<div id="comment">comment</div>-->
</label>
<p></p>
<input type="submit" value="返回主页" id="art-sub">
<input type="button" value="评论" id="write-com">
<input type="button" value="删除该博客" id="delete-com">
</article>
<script type="text/javascript">
var cle=document.getElementById("content");
var ti=document.getElementById("title");
var co=document.getElementById("the-all");
var re=document.getElementById("art-sub");
var de=document.getElementById("delete-com");
var say=document.getElementById("write-com");
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}
function lookBlog(){
var url=location.href;
if(url.search('=')==-1){
ti.innerHTML=getCookie("title");
co.innerHTML=getCookie("content");
}
else{
console.log(decodeURI(url))
url=decodeURI(url);
var theTitle=url.substr(url.indexOf('=')+1);
//console.log(theTitle)
var str=localStorage.getItem("art");
var arr=str?JSON.parse(str):[];
if(arr!=[]){
for(var i=0;i<arr.length;i++){
var title=arr[i].title;
var content=arr[i].content;
if(theTitle==title){
ti.innerHTML=title;
co.innerHTML=content;
}
}
}
}
return ti.innerHTML;
}
var deleteBlogTitle=lookBlog();
var disgussTitle=deleteBlogTitle;
re.onclick=function () {
window.location.href="blog homepage.html?theUserName="+getCookie("username");
}
de.onclick=function () {
console.log(getCookie("username"))
var va=getCookie("username");
if(va=="109002"){
var str=localStorage.getItem("art");
var arr=str?JSON.parse(str):[];
if(arr==[])
alert("您还没有发布任何博客!")
else{
for(var i=0;i<arr.length;i++){
if(deleteBlogTitle==arr[i].title){
arr.splice(i,1);
localStorage.setItem("art",JSON.stringify(arr));
alert("删除成功!")
//window.location.href="blog homepage.html";
window.location.href="blog homepage.html?theUserName="+getCookie("username");
}
}
console.log(arr)
}
}
else{
alert("您不是博主,无权删除!")
}
}
say.onclick=function () {
console.log(getCookie("username"))
var len=getCookie("username").length;
console.log(len)
if(len==0){
alert("请登陆后再评论!")
window.location.href="blog.html";
}
else{
var label = document.createElement("label");
var textarea = document.createElement("textarea");
var input = document.createElement("input");
input.style.textAlign="center";
input.setAttribute("type","button");
input.setAttribute("id","writeConmment");
input.setAttribute("value","发表评论");
textarea.setAttribute("id","myComment");
textarea.style.cols="80";
textarea.style.rows="2";
textarea.setAttribute("placeholder","请输入你的看法:");
label.appendChild(textarea);
label.appendChild(input);
cle.appendChild(label);
var wrc=document.getElementById("writeConmment");
wrc.onclick=function () {
add(disgussTitle,textarea.value)
}
}
}
function add(disgussTitle,content) {
var str=localStorage.getItem("discuss");
var arr=str?JSON.parse(str):[];
var discuss={
"title":disgussTitle,
"content":content
};
arr.push(discuss);
localStorage.setItem("discuss",JSON.stringify(arr));
alert("发表评论成功!")
window.location.reload();
}
function fresh() {
var dis=document.getElementById("dis");
var str=localStorage.getItem("discuss");
var arr=str?JSON.parse(str):[];
if(arr!=[]){
for(var i=0;i<arr.length;i++){
var title=arr[i].title;
var content=arr[i].content;
if(title==disgussTitle){
var div=document.createElement("div");
div.setAttribute("id","comment");
div.innerHTML=content;
dis.appendChild(div);
}
// <label>评论:
// <!--<div id="comment">comment</div>-->
// <!--<div id="comment">comment</div>-->
// <!--<div id="comment">comment</div>-->
// </label>
}
}
}
fresh();
</script>
</body>
</html>