target = E.target | | E.srcelement

Source: Internet
Author: User

Mouse clicks appear drop-down menu, point other Place, shrink back.
Document.addeventlistener ("MouseDown", function (e) {var target = E.target | | e.srcelement;while (target!! Document & & Target! = Popup) {target = Target.parentnode;} if (target = = document) {popup.hide ();}}, False), where popup is a menu element, Popup.hide () hidden menu
Nav.onclick = function () {
var e = Arguments[0] | | Window.event,
target = e.srcelement? E.srcelement:e.target;
}//Some pieces of code how to explain.
Nav is the name of an element of a page, such as a button or picture, etc.. onclick is the register event for this element. Function inside is the code that executes when clicked. where var e = arguments[0] | | The arguments in window.event is the parameter array of the function, that is, all parameters, and Arguments[0] is the first parameter, the first parameter of the Click event (onclick) in the Firefox browser is the event (click Events Object), But IE is not inside, so to make sure that E is "click event Object" so use "| |". You may just want to know that the variable e here is an event object. This event object has some intrinsic properties, such as E.srcelement, which is the object of the event, in layman's name, click Who, here is the first line of the nav element. E.srcelement only Internet Explorer is effective, and in Firefox it should be: e.target, so  target = e.srcelement? e.srcelement:e.target; this line is to make sure The previous target is the event-triggered element, the NAV.

target = E.target | | E.srcelement

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.