javascript 缺少 ) 在括号中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7122430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 23:01:58  来源:igfitidea点击:

missing ) in parenthetical

javascript

提问by Steven

I keep getting that my javascript is missing ) in parenthetical [Break On This Error] if ( (this.scrollTop < this.scrollH...uches[0].pageY > scrollStartPosY+5) )

我不断发现我的 javascript 是 missing ) in parenthetical [Break On This Error] if ( (this.scrollTop < this.scrollH...uches[0].pageY > scrollStartPosY+5) )

function touchScroll(id){
    if(isTouchDevice()){ //if touch events exist...
        var el=document.getElementById(id);
        var scrollStartPosY=0;
        var scrollStartPosX=0;

        document.getElementById(id).addEventListener("touchstart", function(event) {
            scrollStartPosY=this.scrollTop+event.touches[0].pageY;
            scrollStartPosX=this.scrollLeft+event.touches[0].pageX;
            //event.preventDefault(); // Keep this remarked so you can click on buttons and links in the div
        },false);

        document.getElementById(id).addEventListener("touchmove", function(event) {
            // These if statements allow the full page to scroll (not just the div) if they are
            // at the top of the div scroll or the bottom of the div scroll
            // The -5 and +5 below are in case they are trying to scroll the page sideways
            // but their finger moves a few pixels down or up.  The event.preventDefault() function
            // will not be called in that case so that the whole page can scroll.
            if ( (this.scrollTop < this.scrollHeight-this.offsetHeight) && (this.scrollTop+event.touches[0].pageY < scrollStartPosY-5) || (this.scrollTop != 0 && this.scrollTop+event.touches[0].pageY > scrollStartPosY+5) )
                    event.preventDefault(); 
            if ((this.scrollLeft < this.scrollWidth-this.offsetWidth && this.scrollLeft+event.touches[0].pageX < scrollStartPosX-5) || (this.scrollLeft != 0 && this.scrollLeft+event.touches[0].pageX > scrollStartPosX+5))
                    event.preventDefault(); 
            this.scrollTop=scrollStartPosY-event.touches[0].pageY;
            this.scrollLeft=scrollStartPosX-event.touches[0].pageX;
        },false);
    }
}

And I cannot for the life of me figure out why.

我一生都无法弄清楚原因。

采纳答案by Diodeus - James MacFarlane

Try JS Lint. It's great for finding non-obvious syntax errors on scripts.

试试JS Lint。它非常适合在脚本中查找不明显的语法错误。

回答by przemo_li

For me it was +missing in some string concatenation that happened inside ().

对我来说,它+().

回答by zatatatata

It seems according to JSLintthat this script is fine, except for some type conversions, that aren't mandatory to follow. It must be something before this that leaves an open parenthesis.

根据JSLint 的说法,这个脚本似乎很好,除了一些不是强制遵循的类型转换。一定是在这之前留下了一个开放括号的东西。

回答by jmunsch

In my case, I wasn't thinking, and I was:

就我而言,我没有在想,我是:

  • pasting typescriptinto the browser console
  • 粘贴typescript到浏览器控制台

回答by Mike C

Do you have code before what you are showing above? You may have an unclosed paren before this function that javascript is only realizing is unclosed when it gets to this.

您在上面显示的内容之前有代码吗?在此函数之前,您可能有一个未关闭的括号,javascript 仅在到达此函数时才意识到它是未关闭的。