jQuery 可以从我的事件处理程序中抛出错误吗?

发布于 2024-08-19 16:47:35 字数 918 浏览 4 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾旎 2024-08-26 16:47:35

我非常确定 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 undefined qaz in Firebug. Opening up the normal browser error console, I also see the qaz 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文