Srcelement acquisition under IE and FF

Source: Internet
Author: User
Tags object window
The event in IE and the event in FF is not the same, access is not the same, such as IE in the event is the global Window object properties, and FF did not. There are a lot of times when we want to get the source object that triggers the event (srcelement in IE), here are two ways.

When writing JS, we have to consider the compatibility of IE and FF in many cases. Very simply, the event in IE and the event in FF are different

, such as IE, the event is the property of the global Window object, but the FF does not. There are a lot of times we want to get triggers

The source object of the event (srcelement in IE), the following two methods are given.

Passing an event parameter in a function

Passing the event argument in a function so that we can be compatible with IE and FF event acquisition, as in the following function:

function _test (EVT)
{
var src = evt.srcelement evt.target; Gets the source object that triggered the event
alert (Src.value); Print the Value property of this object
}

So we should do this when we use it:

<input type= ' button ' value= ' click me '/>

It can be seen that the second method is more general and universal than the two methods, since it is not possible to pass parameters, so that when used, it is more

Added convenience; The first way is more direct and clear, oh, as for the specific use, but also to look at the individual ~ ~



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.