วันเสาร์ที่ 24 กันยายน พ.ศ. 2554

สร้าง button แสดงและซ่อน DIV Layer


Showing & hiding div layers on button clicks

แบบที่ 1



Here is the demo of controlling the display of layer by using single button
Here is the code of above demo

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<html>
<head>
<title>Demo of Show hide div layer onclick of buttons</title>
<META NAME="DESCRIPTION" CONTENT="Demo for showing and hiding div layers through button clicks">
<META NAME="KEYWORDS" CONTENT="Demo Show layer, Demo hide layer, display div, hide div, button on click, button on click event, div property, div style set">
<style type="text/css">
div {
position: absolute;
left: 250px;
top: 200px;
background-color: #f1f1f1;
width: 280px;
padding: 10px;
color: black;
border: #0000cc 2px dashed;
display: none;
}
</style>


<script language="JavaScript">
function setVisibility(id) {
if(document.getElementById('bt1').value=='Hide Layer'){
document.getElementById('bt1').value = 'Show Layer';
document.getElementById(id).style.display = 'none';
}else{
document.getElementById('bt1').value = 'Hide Layer';
document.getElementById(id).style.display = 'inline';
}
}

</script>
</head>
<body>

<input type=button name=type id='bt1' value='Show Layer' onclick="setVisibility('sub3');";>

<div id="sub3">Message Box</div>
<br><br>
</body>
</html>

แบบที่ 2



Here is a the demo of show hide layer

Here is the code

<html>
<head>
<title>(Type a title for your page here)</title>
<style type="text/css">
div {
position: absolute;
left: 100px;
top: 200px;
background-color: #f1f1f1;
width: 180px;
padding: 10px;
color: black;
border: #0000cc 2px dashed;
display: none;
}
</style>

<script language="JavaScript">
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
</script>

</head>
<body >

<input type=button name=type value='Show Layer' onclick="setVisibility('sub3', 'inline');";><input type=button name=type value='Hide Layer' onclick="setVisibility('sub3', 'none');";>

<div id="sub3">Message Box</div>

</body>
</html>


ไม่มีความคิดเห็น:

แสดงความคิดเห็น