在jQuery中捕获了Uncaught TypeError [英] got Uncaught TypeError in jquery

查看:250
本文介绍了在jQuery中捕获了Uncaught TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div id="divTest1">hi</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script type="text/javascript">
function DocumentReady(event)
{
       console.log(event.type); 
}

$('#divTest1').click(DocumentReady(event));
</script>

问题:

在chrome-> console中,它显示:Uncaught TypeError: Cannot read property 'type' of undefined,那么上述代码出了什么问题?

In chrome->console, it shows:Uncaught TypeError: Cannot read property 'type' of undefined , so what is going wrong with the above codes?

推荐答案

您正在调用DocumentReady并将其结果作为$('#divTest1').click的回调传递.

You're calling DocumentReady and passing its result as the callback for $('#divTest1').click.

只需传递函数:

$('#divTest1').click(DocumentReady);

这篇关于在jQuery中捕获了Uncaught TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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