使用js实现关闭js弹出层的窗口
<script type="text/javascript">
function toggle() {
theObj = document.getElementById('Sunyanzi').style;
if ( theObj.display == "none" ) theObj.display = "block"; else theObj.display = "none";
}
</script>
<div id="Sunyanzi" style="display:none">你看我出现了~~~</div>
<br />
<input type="button" onclick="toggle()" value="点一下试试看 ...?" />
两种方法:去除和隐藏
//创建你的弹出层
var dvMsg = document.createElement("div");
strHtml = "<div class='####'>弹出层内容</div>"
strHtml += " <div class='####'><input type='button' value='关闭' onclick='btnclick()'></div>"
dvMsg.innerHTML = strHtml;
document.body.appendChild(dvMsg);
// 关闭按钮
btnclick = function (){
document.body.removeChild(dvMsg);
-------------------------
或者 弹出层用div id标记
<div id="tanchu">弹出层内容</div>
js里
function open(){
document.getElementById(tanchu).style.display=""; //显示
}
function close(){
document.getElementById(tanchu).style.display="none"; //不显示(页面初始化的时候同样加载一遍)
}