-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageSprite.html
156 lines (137 loc) · 5.75 KB
/
ImageSprite.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
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
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="lianbin">
<title>图灵机器人</title>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<style>
html,
body {
height: 100px;
margin: 0;
padding: 0;
}
main {
width: 80%;
margin: 0 auto;
}
.show {
/* dotted 圆点虚线 */
border-bottom: 5px dotted orangered;
padding-bottom: 10px;
}
.show p {
color: red;
}
#inputContent {
height: 200px;
width: 600px;
border: 1px solid red;
padding: 10px;
}
#inputContent:focus {
outline: none;
}
.addDiv {
border-bottom: 3px dotted lightgreen;
padding: 1px;
}
.blue {
color: blue;
}
.orangered {
color: orangered;
}
</style>
</head>
<body>
<main>
<h1>图灵机器人</h1>
<div class="show">
<p>请再下面的框中输入你要和机器人对话的内容:</p>
<div id="inputContent" contentEditable='true'>
</div>
</div>
<div id="showContent">
</div>
</main>
<script>
// 1.创建 XMLHttpRequest对象
var xhr = new XMLHttpRequest()
// 2.监听请求状态
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
var data = JSON.parse(xhr.responseText)
console.log(data)
// 文本类
if (data.code == '100000') {
$('#showContent').append(`
<div class="addDiv">
<div>
<p><span class="blue">提问:</span><span class="orangered">${$('#inputContent').text()}</span></p>
</div>
<div>
<p><span class="blue">回答:</span><span class="red">${data.text}</span></p>
</div>
</div>
`)
$('#inputContent').html('')
}
// 链接类
if (data.code == '200000') {
$('#showContent').append(`
<div class="addDiv">
<div>
<p><span class="blue">提问:</span><span class="orangered">${$('#inputContent').text()}</span></p>
</div>
<div>
<p><span class="blue">回答:</span><span class="red">${data.text}</span><a href="${data.url}">点我跳转</a></p>
</div>
</div>
`)
$('#inputContent').html('')
}
// 新闻类
if (data.code == '302000') {
$('#showContent').append(`
<div class="addDiv">
<div>
<p><span class="blue">提问:</span><span class="orangered">${$('#inputContent').text()}</span></p>
</div>
<div>
<p>
<span class="blue">回答:</span>
<span class="red">${data.text}</span>
<span>${data.list[0].article}</span>
<a href="${data.url}">点我跳转</a></p>
</div>
</div>
`)
$('#inputContent').html('')
}
// 菜谱类
if (data.code == '308000') {
$('#showContent').append(`
<div class="addDiv">
<div>
<p><span class="blue">提问:</span><span class="orangered">${$('#inputContent').text()}</span></p>
</div>
<div>
<p><span class="blue">回答:</span><span class="red">${data.text}</span><a href="${data.url}">点我跳转</a></p>
</div>
</div>
`)
$('#inputContent').html('')
}
// 在页面加载完再清空输入
}
}
$('#inputContent').keydown(function (e) {
if (e.keyCode == 13) {
xhr.open('get', `http://www.tuling123.com/openapi/api?key=588881add9714a46af72d77349dde62e&info=${$(this).text()}`, true)
xhr.send()
}
})
</script>
</body>
</html>