views:

11

answers:

1

hi! In my program,i write like this:

function handleFuc( event ){
  var a = event.pageX;
  var b = event.pageY;
  var tempdiv = document.createElement("div");
  tempdiv.onmouseout = function(){
    var x = event.pageX;    // 1
    var y = event.pageY;    //
  }
}
var div = document.getElementById( "id" );
div.onmouseover = function(){
  handleFuc( event );
}

now,in function handleFuc, how could i distinguish the two "event"? Thanks! :)

+1  A: 

You could try the following:

 function handleFuc( event , i=0){
  var a = event.pageX;
  var b = event.pageY;
  var tempdiv = document.createElement("div");
  tempdiv.onmouseout = function(){
    var x = event.pageX;    // 1
    var y = event.pageY;    //
  }
 }
 var div = document.getElementById( "id" );
 div.onmouseover = function(){
   handleFuc( event , 1);
 }

So what I did was add another argument to the function, that defaults to 0, and in the second call of the function you set this argument to 1. So if 2nd argument is 0, the 1st event called it, if it is 1, the 2nd one did...

Ladislav

Ladislav

related questions