禁止输入空格
This commit is contained in:
1 parent
a3e4b915d1
commit
6a4316c475
1 file changed
+22
+22
@@ -270,6 +270,19 @@ function joinRoom(username, room, password, modal = null) {
|
||||
roomsData[idx].chat = chatInst;
|
||||
}
|
||||
|
||||
// 禁止输入框输入空格的工具函数
|
||||
function preventSpaceInput(input) {
|
||||
if (!input) return;
|
||||
input.addEventListener('keydown', function(e) {
|
||||
if (e.key === ' ') e.preventDefault();
|
||||
});
|
||||
input.addEventListener('input', function(e) {
|
||||
if (input.value && input.value.includes(' ')) {
|
||||
input.value = input.value.replace(/\s+/g, '');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 打开新房间登录模态
|
||||
function openLoginModal() {
|
||||
const loginContainer = document.getElementById('login-container');
|
||||
@@ -302,6 +315,10 @@ function openLoginModal() {
|
||||
document.body.appendChild(modal);
|
||||
// 关闭按钮
|
||||
modal.querySelector('.login-modal-close').onclick = () => modal.remove();
|
||||
// 禁止弹窗登录页输入框输入空格
|
||||
preventSpaceInput(modal.querySelector('#username-modal'));
|
||||
preventSpaceInput(modal.querySelector('#room-modal'));
|
||||
preventSpaceInput(modal.querySelector('#password-modal'));
|
||||
// 表单提交逻辑,复用loginFormHandler但传入modal
|
||||
const form = modal.querySelector('#login-form-modal');
|
||||
form.addEventListener('submit', function(e) {
|
||||
@@ -494,6 +511,11 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
const joinBtn = document.querySelector('.join-room');
|
||||
if (joinBtn) joinBtn.onclick = openLoginModal;
|
||||
|
||||
// 禁止主登录页输入框输入空格
|
||||
preventSpaceInput(document.getElementById('username'));
|
||||
preventSpaceInput(document.getElementById('room'));
|
||||
preventSpaceInput(document.getElementById('password'));
|
||||
|
||||
setupInputPlaceholder();
|
||||
setupMoreBtnMenu();
|
||||
|
||||
|
||||
Reference in new issue
Block a user