Home > Article > Web Front-end > js implements the window function code for closing the js pop-up layer
This article mainly introduces the sample code for using js to close the window of the js pop-up layer. Friends who need it can come and refer to it. I hope it will be helpful to everyone
<script type="text/javascript"> function toggle() { theObj = document.getElementById('Sunyanzi').style; if ( theObj.display == "none" ) theObj.display = "block"; else theObj.display = "none"; } </script> <p id="Sunyanzi" style="display:none">你看我出现了~~~</p> <br /> <input type="button" onclick="toggle()" value="点一下试试看 ...?" />
Two methods: remove and hide
//创建你的弹出层 var dvMsg = document.createElement("p"); strHtml = "<p class='####'>弹出层内容</p>" strHtml += " <p class='####'><input type='button' value='关闭' onclick='btnclick()'></p>" dvMsg.innerHTML = strHtml; document.body.appendChild(dvMsg); // 关闭按钮 btnclick = function (){ document.body.removeChild(dvMsg);
-------------------------
Or the pop-up layer is marked with p id
<p id="tanchu">弹出层内容</p>
js
function open(){ document.getElementById(tanchu).style.display=""; //显示 } function close(){ document.getElementById(tanchu).style.display="none"; //不显示(页面初始化的时候同样加载一遍) }
The above is the detailed content of js implements the window function code for closing the js pop-up layer. For more information, please follow other related articles on the PHP Chinese website!