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. However, I am getting the pop-up without clicking the link. Anyone knows wher开发者_如何学Pythone the problem lies?
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.
精彩评论