')); // 给当前点击的分页项添加active类 this.classList.add('active'); // 在实际应用中,这里会加载对应页面的新闻 // 这里只是演示,所以没有实际加载内容 }); }); // 订阅表单提交 document.querySelector('.subscription-form').addEventListener('submit', function(e) { e.preventDefault(); const email = this.querySelector('.subscription-input').value; if(email) { alert(`感谢您的订阅!我们将向 ${email} 发送最新资讯。`); this.reset(); } }); // 平滑滚动 document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const targetId = this.getAttribute('href'); if(targetId === '#') return; const targetElement = document.querySelector(targetId); if(targetElement) { window.scrollTo({ top: targetElement.offsetTop - 80, behavior: 'smooth' }); // 移动端点击后关闭菜单 if(window.innerWidth <= 768) { document.querySelector('.nav-menu').classList.remove('active'); } } }); });