开发者

about event handle-function in JavaScript

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! :)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜