In ie, the event object has the srcelement attribute, but does not have the target attribute. In Firefox, the even object has the target attribute, but does not have the srcelement attribute .. Solution: Use OBJ (OBJ = event. srcelement? Event. srcelement: Event.targetexample to replace event.srcelement=event.tar get under firefox .. Pay attention to Compatibility issues.
You can capture the objects of the current event, such as event. srcelement. tagname, to capture the activity tag name. Note that all obtained tags are expressed in uppercase, such as "TD", "TR", and ". So you can copy some of the items you have read and try again if you don't remember them. <SCRIPT type = "text/javasOther "> Function tdclick (){ If (event. srcelement. tagname. tolowercase () = 'td ') Alert ("row:" + (event. srcelement. parentnode. rowindex + 1) + "column:" + (event. srcelement. cellindex + 1 )); } </SCRIPT> Event. srcelement can be seen literally with the following keywords: event, the source means: the source of the current event, We can call various attributes like document. getelementbyid, Some people often ask how to use event. srcelement in Firefox, which is described in detail here: In ie, the event object has the srcelement attribute, but does not have the target attribute. In Firefox, the event object has the target attribute, but does not have the srcelement attribute. However, they play a similar role, namely: Event. srcelement under event.tar get = IE in Firefox Solution: Use OBJ (OBJ = event. srcelement? Event. srcelement: event.targettoken used to replace event.tar get under firefox. In You can directly use the window. event object to process events in IE, but in Firefox, there is no Window. when an event object is used by a function, the event must be passed as a parameter when an event occurs. Unlike in IE, the event object is global and can be accessed everywhere. Q. The following getevent () function is compatible with Firefox and IE. You only need to call getevent () at the beginning of the function that accesses the event object. You no longer need to use the event Parameter transfer:CodeThe experiment has passed!
Function myfunc () { VaR EVT = getevent (); VaR element = EVT. srcelement | evt.tar get; } Function getevent () { If (document. All) { Return window. event; // for IE } Func = getevent. Caller; While (func! = NULL) { VaR arg0 = func. Arguments [0]; If (arg0) { If (arg0.constructor = event | arg0.constructor = mouseevent) | (Typeof (arg0) = "object" & arg0.preventdefault & arg0.stoppropagation )) { Return arg0; } } Func = func. Caller; } Return NULL; } |