我有一个错误,发生在我使用jQuery设置的特定事件处理程序中,并且代码只是中断而没有显示任何错误。当我用YUI编写类似的东西时,我会设置YAHOO.util.Event.throwErrors = true;在我的开发中。版本,这是告诉YUI的事件处理程序抛出错误。我找不到任何类似的东西,难道只是我瞎了眼,看不到它?jQuery可以从我的事件处理程序中抛出一个错误吗?
谢谢!
下面是一个例子...
<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>
如果我运行这段代码,两个事件处理程序都会触发&'console.log'写出firebug,然后死在'qaz'上是未定义的......这不是您所期望的吗? – Alconja 2010-01-28 22:33:25
我想这个例子有点令人困惑,现在我改变了它,所以它更清楚我在找什么。如果再次运行它,则只会看到一个console.log被写出,并且没有错误报告。这是我期望jQuery能够正常工作的方式,但是我想知道是否有办法使它在qaz上报告错误;使调试更容易? – SBUJOLD 2010-01-28 23:41:18
你的意思是Javascript吗? jQuery不处理语言级错误。这是一个函数库。 – 2011-06-13 14:41:53