我有一個錯誤,發生在我使用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