JavaScript pop-up layer click anywhere Close method

Source: Internet
Author: User
  
  
The code is as follows Copy Code
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> Click anywhere else to close div</title>

<body>
<input type= "text" value= "" id= "TF"/>
<div style= "width:400px; height:200px;border:1px solid #000;d isplay:none "id=" con ">
<p>1111</p>
<p><span>2222</span></p>
<p><a href= "#" >3333</a></p>
</div>
<script>
function e (obj) {return document.getElementById (obj)}
E (' TF '). Onclick=function (Event) {
E (' con '). style.display= ' block ';
Stopbubble (event);
Document.onclick=function () {
E (' con '). style.display= ' None ';
Document.onclick=null;
}
}

E (' con '). Onclick=function (Event) {
Only blocks upward bubbling without blocking downward capture, so you can still execute this function when you click on the internal object of con
Stopbubble (event);
}
Block Bubble function
function Stopbubble (e) {
if (e && e.stoppropagation) {
E.stoppropagation (); W3c
}else{
Window.event.cancelbubble=true; Ie
}
}
</script>
</body>

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.