找不到 JavaScript 语法错误
我简直要惊慌失措了。我目前必须在其他人做的一个网站上工作,我被要求维护等等。它使用 jQuery 和一堆 drupal 模块。在某些点上,我遇到了一些语法错误,因此有些js可以工作,有些则不能。我最大的问题是找到语法错误。 Firebug 和 WebInspector 都没有给我提供像样的信息:
Error: uncaught exception: Syntax error, unrecognized expression: //
是的……就是这样。没有行,没有文件名,没有更多的提示。有谁知道如何处理这个问题?
感谢您提供任何有用的提示。
I'm just about to freak out. I currently have to work on a website that some other guy did and I am asked to maintain etc. It uses jQuery and a bunch of drupal modules. At some point i get some syntax error, so that some js works, and some does not. My big big problem is to find the syntax error. Neither Firebug, nor WebInspector give me decent information:
Error: uncaught exception: Syntax error, unrecognized expression: //
Yeah… that's it. No lines, no filename, no more hints. Has anyone an idea how to deal with this?
Thanks for any usefull hints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试像闭包编译器这样的工具,它会针对代码块发出警告和错误。否则,使用
alert('checkpoint');
来确定在出现问题之前代码的执行程度是蛮力的。you might try a tool like the closure compiler, which will give warnings and errors for blocks of code. otherwise, it's brute force with
alert('checkpoint');
to determine how far into your code you get before things break.我相信 Chrome 的控制台可以查明错误所在的行......右键单击页面 >检查元素,然后在弹出的窗口右下角,单击红色 X 图标,然后单击错误的链接,必要时启用资源跟踪...
另外,将代码放入 JSLint 并更正相应的代码...
I believe Chrome's console pinpoints the line of the error.... Right-click on the page > Inspect element, then in the bottom right corner of the window that pops up, click on the red X icon, then click on the link for the error, enable Resource tracking if necessary...
Also, put the code trough JSLint and correct the code accordingly ...
如果可能的话,我首先会在 html 中一次注释掉除一个 javascript 之外的所有内容(除非它们是一团混乱的依赖关系)。除此之外,您可以尝试使用调试器逐行调试它吗?最后,如果工作量不大,也许值得编写单元测试。它还将帮助您完全理解该人的代码,并可能识别任何更深层次的逻辑级错误。
I'd start by commenting out all but one javascript include at a time in the html, if possible (unless they're a tangled mess of dependencies). Other than that, can you try using a debugger to step through it line by line? Finally, if it's not too much work, maybe it's worth writing unit tests. It'll also help you fully understand the person's code, and probably identify any deeper logic-level bugs.
JSLint 可能是您所需要的,但我敢打赌它会发现更多的问题,而不仅仅是您难以捉摸的语法错误。
JSLint may be what you need, but I bet it finds a lot more problems than just your elusive syntax error.