在jquery中得到了Uncaught TypeError

时间:2013-07-08 01:42:09

标签: jquery

<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-&gt;控制台中,它显示:Uncaught TypeError: Cannot read property 'type' of undefined,那么上述代码出了什么问题?

1 个答案:

答案 0 :(得分:1)

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

只需传递功能:

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