想问一下我做了2个div之间的跳转操作,div之间跳转行为用a标签 href="#"进行跳转,但是我的本意是想做链接来进行跳转操作,不知道为什么点击div的空白处也会进行div的跳转行为 .container { display: flex; justify-content: space-between; } .box { width: 500px; height: 500px; text-align: center; line-height: 100px; color: white; font-size: 18px; cursor: pointer; display: block; } #box1 { background-color: red; } #box2 { background-color: blue; display: none; } #box3 { background-color: green; display: none; } Click to go to Box 2 Click to go to Box 3 You are in Box 3 function handleContainerClick(event) { // 获取点击的元素 const target = event.target; // 判断点击的是否为链接(a 元素) if (target.tagName.toLowerCase() === 'a') { // 链接的默认行为会继续执行 return; } // 如果点击的是包含链接的盒子,则执行链接跳转 if (target.classList.contains('box')) { const boxId = target.id; showBox(boxId); } } function showBox(boxId) { // 隐藏所有的盒子 document.getElementById('box1').style.display = 'none'; document.getElementById('box2').style.display = 'none'; document.getElementById('box3').style.display = 'none'; // 显示指定的盒子 document.getElementById(boxId).style.display = 'block'; } 我做了if判断也没用