event.srcElement And event.target The difference between

window.event.srcElement And window.event.target They all point to the element that triggers the event. It has the same attributes as it is

Srclelement is the target HTML element object reference of event initialization, because events bubble through the element hierarchy and can be processed at any layer

With a reference to an element, you can read, write, and change the attributes of the element.

IE browser support window.event.srcElement And firebox supports window.event.target ;

event.srcElement Literally, there are the following keywords: event, Source: the source of the current event,
we can call its various properties, such as: document.getElementById (“) for such functions,
people often ask about the event.srcElement How to use it is explained in detail here:
in ie, the event object has the srclelement attribute but no target attribute; in Firefox, the event object has the target attribute, However, there is no srclelement attribute, but their functions are equivalent, that is:
in firebox event.target =Under IE event.srcElement

Solution: use obj (obj)= event.srcElement ? event.srcElement : event.target ; )Instead of IE event.srcElement Or in Firefox event.target .

in JS, this and window.event.srcElement [the following content is reprinted]

let’s start with a simple example:

<input type=”text”
onblur=”alert( this.value ) “/ &> no problem at all.

under what circumstances can it not be used?

fuction method()


alert( this.value );


≪ input type = “text”
onblur = method() “/ &> this is not OK, because method() is a function called by the response function.

what should we do in this case?

method 1:

fuction method(btn)


alert( btn.value );


≪ input type = “text” onblur = method (this) “/ &> no problem!

method 2:

fuction method()


alert( window.event.srcElement .value);


≪ input type = “text”
onblur = method() “/ &> no problem! window.event.srcElement Gets the control that triggers the event

Similar Posts: