您可以尝试以下代码来实现点击链接时其他链接消失的效果:

let all = document.querySelectorAll('a');

all.forEach(item => item.addEventListener('click', function() {
  // 隐藏其他链接
  all.forEach(link => {
    if (link !== item) {
      link.style.display = 'none';
    }
  });
}));

这段代码会给所有的链接添加点击事件监听器。当点击某个链接时,会隐藏其他所有链接。

let all = documentquerySelectorAlla		allforEachitem=itemaddEventListenerclickfunction		自身点击的时候其他消失

原文地址: https://www.cveoy.top/t/topic/iCWU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录