javascript按键按下问题
我的一个文本框附加了一个按键事件,随着时间的推移以及第三方脚本的修改/添加,按键不再起作用。我尝试用上键/按键替换下键,但没有成功。
你会如何解决这样的问题(对我来说,这就像大海捞针)。
I have a key down event attached to one of my textboxes and over time and modifications/additions of 3rd party scripts the key down doesn't work any more. I've tried replacing key down with key up/key press but no luck.
How would you trouble shoot something like this (to me, it's like a needle in the haystack).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在处理 KeyDown 事件的 Javascript 代码中,在代码前添加“调试器”,然后您就可以调试 JavaScript。
如果您使用的是 IE,那么在“工具”-“高级”中,您必须确保未选中“禁用脚本调试”,否则它不会在您的调试点停止。
如果您使用 Visual Studio 2010,则内置了一个简洁的 JavaScript 调试器:)
in your Javascript code where you handle the KeyDown event, add "debugger" before your code, and you'll be able to debug JavaScript.
If you're using IE, then in Tools - Advanced, you must make sure that "disable script debugging" is not checked, or it won't stop at your debug point.
If you use Visual Studio 2010, there's a neat JavaScript debugger built in :)
对我来说,解决问题的最佳方法是开始排除一切不必要的东西,让我工作。在这种情况下,开始一次删除所有第三方脚本和额外代码,同时在每次删除某些内容时尝试它是否有效。迟早你会发现代码的哪一部分导致了这个问题,然后你就可以担心如何修复它。
如果您可以发布代码链接,将会有所帮助。
To me the best approach to troubleshooting is start taking out everything is not necessary to make i work. In this case, start deleting all the 3rd party scripts and extra code one at a time, while you try if it works or not every time you delete something. Sooner or later you will find what part of the code is causing this, then you can worry about how to fix it.
It would help if you could post a link to your code.
有几种方法可以做到这一点。是否存在 JavaScript 错误?
如果没有错误表明某行代码不好,那么我将消除第三方脚本,以便您的脚本按预期工作。然后,一次添加一个脚本,不断检查您的 keydown 是否仍然有效。
一旦您知道哪个脚本干扰了 keydown 功能,您就可以开始使用注释和警报来隔离该第三方脚本中的问题。
There are a couple of ways you could do it. Is there a javascript error?
If there is no error to indicate a line of code that's bad, then I would eliminate the thrid party scripts so that your script works as intended. Then, add in the scripts one at a time, continuously checking to see if your keydown still works.
Once you know which script is messing with the keydown functionality you can then start using comments and alerts to isolate the issue in that third party script.