当前位置:

休宁体育赛事,实时直播,为您呈现第一时间的精彩

来源:24直播网
休宁体育赛事
<script> // WebSocket 聊天功能const socket = new WebSocket('ws://localhost:8080');// 聊天记录const chatMessages = document.querySelector('.chat-box ul');// 聊天输入框const chatInput = document.querySelector('.chat-input input');// 发送聊天消息chatInput.addEventListener('keypress', (event) => {if (event.key === 'Enter') {const message = chatInput.value;socket.send(message);chatInput.value = ''; }});// 接收聊天消息socket.addEventListener('message', (event) => {const message = event.data;const li = document.createElement('li');li.textContent = message;chatMessages.appendChild(li);}); </script>