[英]jQuery Click Event Triggering without Clicking
I am facing a tricky problem with my code and hope to get some help on this. 我的代码面临一个棘手的问题,希望对此有所帮助。 Below is a snippet of my code:
以下是我的代码片段:
<SCRIPT type='text/javascript'>
function list(json) {
// list result
$('#pop-up').click(alert(json.length));
}
// declare map and options
google.maps.event.addListener(map, 'idle', function () {
var query = 'some query';
$.getJSON(query, list);
});
</SCRIPT>
<A href='javascript:void(0)' id='pop-up'>Click Me</A>
As seen, the pop-up is supposed to return the length of json object when the pop-up link is clicked. 如图所示,当单击弹出链接时,弹出窗口应返回json对象的长度。 However, I am getting the pop-up without clicking the link.
但是,我没有单击链接就弹出了 。 Anyone knows where the problem lies?
有人知道问题出在哪里吗?
It's because you're using .click()
rather than .click(function() {})
. 这是因为您使用的是
.click()
而不是.click(function() {})
。 Replace the $('#pop-up')
line with: 将
$('#pop-up')
行替换为:
$('#pop-up').click(function() { alert(json.length) });
and get rid of the curly brace underneath that line. 并摆脱那条线下面的花括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.