To determine the element that triggered the event:
var tag = Window.event.target | | Window.event.srcElement;
if (tag.tagName.toLowerCase () = = "Input") {
Return
}
Window.event.srcElement and Window.event.target are all elements that point to the triggering event and what kind of property it is.
Srcelement is an event initialization target HTML element object reference because the event bubbles through the element hierarchy and can be processed at any level.
With the reference to the element, you can read and write the attributes of the element.
IE browser supports window.event.srcElement, while Firefox supports Window.event.target;
In JS this and window.event.srcelement:[a bit of content for reprint]
Let's look at a simple example:
<input type= "text" onblur= "alert (this.value)"/> No problem at all.
So what's not going to work?
Fuction method ()
{
alert (this.value);
}
<input type= "text" onblur= "Method ()"/> This is not possible, because method () is a function called by the response function.
So what happens in this case?
Method One:
Fuction Method (BTN)
{
alert (Btn.value);
}
<input type= "text" onblur= "method (This)"/> No problem!
Method Two:
Fuction method ()
{
alert (Window.event.srcElement.value);
}
<input type= "text" onblur= "Method ()"/> No problem! Window.event.srcElement the control that gets the trigger event
We're looking at an example of a little bit of a detour.
<script type= "Text/javascript" >
function Initevent () {
var inputs = Document.getelementsbytagname_r ("input");
for (var i = 0; i < inputs.length; i++) {
Inputs[i].onblur = onblurevent;
}
}
function Onblurevent () {
//Onblurevent is a onblur response function, not a function called by a response function
//So you can use this to get the object where the event occurred
if (This.value.length > 0) {
This.style.backgroundColor = "White";
}
else {
This.style.backgroundColor = "Red";
}
}
</script>
<body onload= "initevent ()" >
<input id= "Text1" type= "text"/>
<input id= "Text2" type= "text"/>
<input id= "Text3" type= "text"/>
</body>
As shown in the red commentary, you can use this to get input for the current trigger event.
Window.event.srcElement and Window.event.target trigger event object Acquisition (very important)