jQuery 可以从我的事件处理程序中抛出错误吗?
我在使用 jQuery 设置的特定事件处理程序中发生了错误,并且代码只是中断而没有显示任何错误。当我过去在 YUI 中编写类似的代码时,我会设置 YAHOO.util.Event.throwErrors = true;在我的开发中。 version 并且告诉 YUI 的事件处理程序抛出错误。我找不到类似的东西,难道只是我瞎了没有看到它?
谢谢!
这是一个例子...
<html>
<head>
<title>jQuery Events</title>
</head>
<script src="https://www.google.com/jsapi"></script>
<script>
google.load('jquery', '1.3.2');
</script>
<body>
<p>click me</p>
<script type="text/javascript">
$(document).ready(function() {
$("p").click(function() {
console.log('How to display an error here similar to the native onclick ?');
qaz;
console.log('this line is not executed because of the error, but the error is not reported. Is there a way to have jQuery report those errors ?');
});
});
</script>
</body>
</html>
I have an error that occurs in a specific event handler that I setup using jQuery and the code just breaks without any errors being displayed. When I used to code similar things in YUI I would setup YAHOO.util.Event.throwErrors = true; in my dev. version and that was telling YUI's event handler to throw errors. I can't find anything similar, is it just me being blind and not seeing it ?
Thanks!
Here's an example...
<html>
<head>
<title>jQuery Events</title>
</head>
<script src="https://www.google.com/jsapi"></script>
<script>
google.load('jquery', '1.3.2');
</script>
<body>
<p>click me</p>
<script type="text/javascript">
$(document).ready(function() {
$("p").click(function() {
console.log('How to display an error here similar to the native onclick ?');
qaz;
console.log('this line is not executed because of the error, but the error is not reported. Is there a way to have jQuery report those errors ?');
});
});
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我非常确定 jQuery 不会为您吞下错误,因此您肯定应该从未定义的
qaz
中看到错误。运行更新后的页面,我仍然看到
console.log
和 Firebug 中未定义的qaz
上的错误。打开正常的浏览器错误控制台,我还看到qaz is not Defined (...temp.html - Line: 15)
消息。在 IE 中,我当然得到“console”未定义
,但这只是表明错误也在那里发生(因为没有控制台)。假设您正在运行完全相同的 html/js 片段,显然还有其他一些变量在起作用,这会给您带来问题。您运行的是哪个版本的 Firebug?我在调试 javascript 时遇到了各种随机问题。与 1.4.x 版本类似,但 1.5.0 似乎更加一致和稳定。
I'm pretty certain that jQuery won't swallow errors for you, so you should definitely be seeing the error from your undefined
qaz
.Running your updated page, I still see both the
console.log
and the error on the undefinedqaz
in Firebug. Opening up the normal browser error console, I also see theqaz is not defined (...temp.html - Line: 15)
message there too. In IE, I of course get"console" is undefined
, but that just shows that errors are getting through there as well (since there's no console). Assuming you're running that exact same piece of html/js, there's obviously some other variable in play that is causing issues for you.What version of Firebug are you running? I had various random issues with debugging javascript & the like with version 1.4.x, but 1.5.0 seems much more consistent and stable.