diff --git a/平台web/index.html b/平台web/index.html index efa87cc..c040109 100644 --- a/平台web/index.html +++ b/平台web/index.html @@ -331,6 +331,7 @@ menuItems.forEach(item => { item.addEventListener('click', function(e) { e.preventDefault(); + e.stopPropagation(); // 阻止事件冒泡到父级 // 切换子菜单的显示状态 const submenu = this.nextElementSibling; @@ -338,24 +339,27 @@ }); }); - // 为所有菜单项添加点击事件(包括子菜单项) + // 为所有菜单项添加点击事件(仅子菜单项会加载页面) const allMenuItems = document.querySelectorAll('.menu-item a, .submenu-item a'); allMenuItems.forEach(item => { item.addEventListener('click', function(e) { - // 移除所有菜单项的活动状态 - allMenuItems.forEach(i => i.classList.remove('active')); - - // 为当前点击的菜单项添加活动状态 - this.classList.add('active'); - // 获取菜单项文本 const text = this.querySelector('span').textContent; - // 更新内容区域标题 - document.querySelector('.content-header h1').textContent = text || '内容管理系统'; - - // 这里可以根据需要更新内容区域的内容 - updateContent(text); + // 只有子菜单项点击才会加载页面 + if (this.parentElement.classList.contains('submenu-item')) { + // 移除所有菜单项的活动状态 + allMenuItems.forEach(i => i.classList.remove('active')); + + // 为当前点击的菜单项添加活动状态 + this.classList.add('active'); + + // 更新内容区域标题 + document.querySelector('.content-header h1').textContent = text || '内容管理系统'; + + // 这里可以根据需要更新内容区域的内容 + updateContent(text); + } }); });