-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
38 lines (31 loc) · 1000 Bytes
/
index.html
File metadata and controls
38 lines (31 loc) · 1000 Bytes
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>HTML5 WebSocket</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
$(function() {
var socket = io();
var message = $('#message');
$('#emit').on('click', e => {
socket.emit('chat', message.val());
message.val('');
});
socket.on('chat', msg => {
$('#chat').append('<li>' + msg + '</li>');
});
socket.on('disconnect', e => {
socket.close();
});
});
</script>
</head>
<body>
<h1>WebSocket Chat</h1>
<input id="message" />
<button id="emit">送信</button>
<ul id="chat" />
</body>
</html>