内部链接 return 个空错误,我在 Javascript 中找不到错误。外部链接工作得很好

Internal links return null errors and I can't find the mistake in my Javascript. External links work just fine

我建立了一个网站并尝试了一个花哨的导航,我从 http://codepen.io/arjancodes/pen/jErbyM 复制并定制了一点。 (谢谢你给了我灵感!)

这是我的网站

davidgoossens.com

HTML 和 CSS 工作正常但内部链接(当您打开右下角的导航时)不断返回 404。 我的网站托管商告诉我错误一定在 JS 中,它是:

 var nav = document.querySelector('.material-menu-wrapper');
 var circle = document.querySelector('.material-btn');
 var link = document.querySelector('.material-content').querySelectorAll('li');
 var ham = document.querySelector('.material-hamburger');
 var main = document.querySelector('.content-fade');



var win = window;

function openMenu(event) {
  nav.classList.toggle('active');
  circle.classList.toggle('active');
  ham.classList.toggle('material-close');
  main.classList.toggle('active');
  for (var i = 0; i < link.length; i++) {
    link[i].classList.toggle('active');
  }
  event.preventDefault();
  event.stopImmediatePropagation();
}

function closeMenu() {
  if (circle.classList.contains('active')) {
    circle.classList.remove('active');
    for (var i = 0; i < link.length; i++) {
      link[i].classList.toggle('active');
    }
    ham.classList.remove('material-close');
    main.classList.remove('active');
    nav.classList.remove('active');
  }
}


circle.addEventListener('click', openMenu, false);
circle.addEventListener('touchstart', openMenu, false);
win.addEventListener('click', closeMenu, false);
win.addEventListener('touchstart', closeMenu, false);`    

这是我的导航HTML

<div class="material-menu-wrapper">
  <div class="material-menu">
    <div class="material-btn">
      <div class="material-hamburger">
        <div class="material-patty"></div>
        <div class="material-patty"></div>
        <div class="material-patty"></div>
      </div>
    </div>
    <div class="material-content">
      <nav>
        <ul>
          <li><a href="http://davidgoossens.com/thesen.html">Thesenpapier</a></li>
          <li><a href="http://davidgoossens.com/motivation.html">Motivation</a></li>
          <li><a href="http://davidgoossens.com/work.html">Arbeitsproben</a></li>
          <li><a href="http://davidgoossens.com/cv.html">CV</a></li>

        </ul>
      </nav>
    </div>
  </div>
</div>

如果你能帮我解决这个问题就太好了!!!

此致

大卫

你的问题在clickdelay.js:

$(function(){ // DOM READY shorthand

  $('li').click(function (e) {

    e.preventDefault();
    var goTo = this.getAttribute("href");


    //< do something

    //do something > 


     setTimeout(function(){
       window.location = goTo;
    },500);

   }); 
});
此代码中的

thisli 元素,而不是 link。当您尝试获取 li 的 href 时,它会失败并且 goTo 为空。那么你有window.location = null;。需要获取子元素的href,锚标签。