Javascript 为什么我会得到未捕获的引用错误:scrollToM未定义?

Javascript 为什么我会得到未捕获的引用错误:scrollToM未定义?,javascript,jquery,Javascript,Jquery,我将此代码制作为一页:- $(window).load(function() { function filterPath(string) { return string .replace(/^\//,'') .replace(/(index|default).[a-zA-Z]{3,4}$/,'') .replace(/\/$/,''); } $('a[href*=#]').each(function() { if ( filter

我将此代码制作为一页:-

$(window).load(function() {
  function filterPath(string) {
    return string
      .replace(/^\//,'')
      .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
      .replace(/\/$/,'');
  }

  $('a[href*=#]').each(function() {
    if ( filterPath(location.pathname) == filterPath(this.pathname)
        && location.hostname == this.hostname
        && this.hash.replace(/#/,'') ) {
            var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
            var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : true;
            if ($target) {
                var targetOffset = $target.offset().top + 50;
                $(this).click(function(e) {
                    e.preventDefault();
                    $('html, body').animate({scrollTop: targetOffset}, 1400);
                    var d = document.createElement("div");
                    d.style.height = "90%";
                    d.style.overflow = "hidden";
                    document.body.appendChild(d);
                    window.scrollTo(0,scrollToM);
                    setTimeout(function() {
                        d.parentNode.removeChild(d);
                    }, 10);
                    return false;
                 });
             }
         }
     });
});
有以下错误显示给我:-

未捕获引用错误:未定义scrollToM


您使用的
window.scrollTo(0,scrollToM)的解决方案是什么好的,定义它。或者不说,;它是
y坐标
。使用拼写检查器。如果你是在真正的电脑(而不是手机)上通过现代浏览器发帖,那么编辑应该已经在突出显示拼写错误的单词了。