Get Login button and the entire login panel, add events to the Login button, click on the login layer, click the login Panel Close button, close the entire login layer
After clicking Sign in:
<!doctype html>
<meta charset= "UTF-8" >
<title>Document</title>
<style>
*{margin:0;padding:0;}
. head{font-size:12px;padding:6px 0 0 10px;}
#login_box {width:300px;height:150px;background: #eee;
border:1px solid #ccc;p Osition:absolute;left:50%;top:50%;margin-left:-150px;margin-top:-75px;display:none;}
#login_box p{height:20px;border-bottom:1px solid #ccc; font-size:12px;padding:6px 0 0 5px;font-weight:bold;}
#close {width:14px;height:14px;background:url (close.png) no-repeat;position:absolute;right:4px;top:6px;}
</style>
<script>
Window.onload=function () {
var Login_btn=document.getelementbyid (' login '),
Login_box=document.getelementbyid (' Login_box '),
Close=document.getelementbyid (' close ');
//Package Add Event listener
function Addevent (ele,type,hander) {
if (ele.addeventlistener) {
Ele.addeventlistener (type,hander,false);
}else if (ele.attachevent) {
ele.attachevent (' on ' +type,hander);
}else{
ele[' on ' +type]=hander;
}
}
Show Login Layer Functions
function Showlogin () {
login_box.style.display= ' block ';
}
Hide Login Layer Functions
function Hidelogin () {
Login_box.style.display= ' None ';
}
//Click the login button to display the login layer
addevent (login_btn, ' click ', Showlogin);
//Click the Close button to hide the login layer
addevent (Close, ' click ', Hidelogin);
}
</script>
<body>
<div class= "Head" > Pro, Hello! <input type= "button" value= "Login" id= "Login" ></div>
<div id= "Login_box" >
<p> User Login </p><span id= "Close" ></span>
</div>
</body>
Exercises: Get the login button and the entire login panel, to add events to the Login button, click on the login layer, click the login Panel Close button, close the entire login layer