jQuery可以从我的事件处理程序中引发错误吗? [英] Can jQuery throw an error from my event handlers?

查看:110
本文介绍了jQuery可以从我的事件处理程序中引发错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个错误,发生在我使用jQuery设置的特定事件处理程序中,代码只是中断而没有显示任何错误。当我习惯于在YUI中编写类似的东西时,我将设置YAHOO.util.Event.throwErrors = true;在我的开发版本,这是告诉YUI的事件处理程序抛出错误。我找不到类似的东西,只是我是盲目的,没有看到它?

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 ?

谢谢!

这是一个例子...

<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>


推荐答案

我很确定jQuery不会吞下错误为您,所以您一定要看到您未定义的 qaz 中的错误。

I'm pretty certain that jQuery won't swallow errors for you, so you should definitely be seeing the error from your undefined qaz.

运行更新的页面,我仍然在Firebug中看到 console.log 和未定义的 qaz 上的错误。打开正常的浏览器错误控制台,我也看到 qaz没有定义(... temp.html - Line:15)消息。在IE中,我当然会得到console是未定义的,但这只是表明错误也在通过(因为没有控制台)。假设你正在运行完全相同的html / js,那么显然有一些其他的变量可能会导致你的问题。

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.

你正在运行什么版本的Firebug ?我有不同的随机问题调试javascript&像1.4.x一样,但1.5.0似乎更加一致和稳定。

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.

这篇关于jQuery可以从我的事件处理程序中引发错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆