-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
46 lines (44 loc) · 921 Bytes
/
index.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
<style>
body {
font-family: sans-serif;
font-size: 13px;
}
form {
background: #eee;
padding: 3px;
position: fixed;
bottom: 0;
width: 100%;
}
form input {
padding: 10px;
width: 90%;
}
form button {
padding: 10px;
width: 9%;
}
</style>
<h1>ソフトウェアデザイン Chat example</h1>
<ul id="messages"></ul>
<form id='form'>
<input id="chat" /><button>Chat</button>
</form>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
var form = document.getElementById('form');
var chat = document.getElementById('chat');
var messages = document.getElementById('messages');
form.addEventListener('submit', function (e) {
e.preventDefault();
var message = chat.value;
socket.emit('chat', message);
chat.value = '';
});
socket.on('chat', function (msg) {
var li = document.createElement('li');
li.textContent = msg;
messages.appendChild(li);
});
</script>