javascript - jQuery Click Event Triggering without Clicking - Stack Overflow

I am facing a tricky problem with my code and hope to get some help on this. Below is a snippet of my c

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. However, I am getting the pop-up without clicking the link. Anyone knows where the problem lies?

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. However, I am getting the pop-up without clicking the link. Anyone knows where the problem lies?

Share Improve this question asked Sep 18, 2011 at 11:49 Question OverflowQuestion Overflow 11.3k20 gold badges81 silver badges113 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

It's because you're using .click() rather than .click(function() {}). Replace the $('#pop-up') line with:

$('#pop-up').click(function() { alert(json.length) });

and get rid of the curly brace underneath that line.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745611725a4635984.html

相关推荐

  • javascript - jQuery Click Event Triggering without Clicking - Stack Overflow

    I am facing a tricky problem with my code and hope to get some help on this. Below is a snippet of my c

    10小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信