1

I've searched around and couldn't find anything that really helped much on this.

I'm trying to make a script that records the coordinates of mouse click's that have the coordinate 0 in it so for example x=0 y=125 NOT X=100 y=125 And when it detects coords like that I want it to add them to my mysql database like this.

Username - the user who hit the coord

x - x coordinate

y - y coordinate

amount - how many times they hit that coord

Anyone think they could help me with this?

Updated with code.

<script>

$(document).ready(function(){

    $('.map').click(function(e){
        alert('x pos: ' +  e.pageX + ';  y pos: ' + e.pageY + ';'); 
        if(e.pageX == 0 || e.pageY ==0){
            <?php
    mysql_query("INSERT INTO clickmap (id) VALUES ('".$_SESSION['username']."')")
     or die(mysql_error());  
?>
        }
    }); 
}); 

</script>
4

1 回答 1

1

A jquery solution (assuming someones using a browser) would be to bind a click event to the thing you want to listen to, then use the event that triggered's pageX and pageY like so:

if(e.pageX == 0 || e.pageY == 0) {
//do stuff.  
}

this is a working fiddle:

http://jsfiddle.net/XdLJ9/

于 2013-03-30T00:07:00.883 回答