JS Learning Summary----Event delegates and event proxies

Source: Internet
Author: User

1. What is an event delegate/event Agent

Using the bubbling propagation mechanism of events (triggering the behavior of the current element, the related behavior of all the elements of its parent will be triggered), if there are many elements in a container to bind the point-click event, we do not need to bind each other, only to the outermost container to bind a click event, when this method executes, Different actions are performed by the distinction of the event source.

Specific small cases are as follows:  

<!     DOCTYPE html>{margin:0; padding:0; Font-size:14px; } html,body{Width:100%; Height:100%;        Overflow:hidden;            } #box {Position:absolute; Left:50%;            top:50px;            width:100px;            height:30px; Margin-left:-50px; Line-height:30px; Text-Align:center;        border:1px solid #2489cc;            } #mark {Position:absolute;            top:30px; Left:-1px;            width:300px;            height:100px; Line-height:100px; Text-Align:center;            Background: #ffe470;        border:1px solid #2489cc; }    </style>View Shopping Cart details</div> </div> <script>varMark = document.getElementById (' Mark '); Document.body.onclick=function(e) {e= e | |window.event; E.target= E.target | |e.srcelement; //If you click on a box or a span under #box, we determine if Mark shows it, show it to hide it, and let it show            if(e.target.id=== "box" | | (e.target.tagname.tolowercase () = = = "span" && e.target.parentnode.id=== ' box ')){                if(Mark.style.display = = = "None") {Mark.style.display= = = "Block"                }Else{Mark.style.display= = = "None"                }                return; }            //If the event source is #mark, do not take any action            if(e.target.id=== "Mark"){                return; } Mark.style.display= = = "None"        }    </script></body>

JS Learning Summary----Event delegates and event proxies

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.