发送 <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>