admin管理员组

文章数量:1025227

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.

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.

本文标签: javascriptjQuery Click Event Triggering without ClickingStack Overflow