最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - jQuery Click Event Triggering without Clicking - Stack Overflow

matteradmin8PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far