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

时间:2010-01-28 22:10:24

标签: jquery events yui

我在使用jQuery设置的特定事件处理程序中发生错误,代码只是在没有显示任何错误的情况下中断。当我以前在YUI中编写类似的东西时,我会设置YAHOO.util.Event.throwErrors = true;在我的开发中。版本,这告诉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>

1 个答案:

答案 0 :(得分:1)

我很确定jQuery不会为你吞下错误,所以你肯定会看到未定义qaz的错误。

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

你在运行什么版本的Firebug?我有调试javascript和amp;的各种随机问题。与版本1.4.x类似,但1.5.0似乎更加一致和稳定。