js实现弹窗

来源:互联网 发布:可以看腐剧的软件 编辑:程序博客网 时间:2024/06/05 11:25
<div id=win style="display:none; POSITION:absolute; left:50%; top:50%; width:600px; height:400px; margin-left:-300px; margin-top:-200px; border:1px solid #888; background-color:#edf; text-align:center">这是DIV登录框示例<br><a href="javascript:closeLogin();">关闭登录框</a></div>
<script>
function openLogin(){
document.getElementById("win").style.display="";
}
function closeLogin(){
document.getElementById("win").style.display="none";
}
</script>
<a href="javascript:openLogin();">打开登录框</a>

追答
<script>function openLogin(){   document.getElementById("win").style.display="";   document.getElementById("back").style.display="";}function closeLogin(){   document.getElementById("win").style.display="none";   document.getElementById("back").style.display="none";}</script><a href="javascript:openLogin();">打开登录框</a><div id=back style="display:none; POSITION:absolute; left:0; top:0; width:100%; height:100%; background-color:#000; filter:alpha(opacity=60)"></div><div id=win style="display:none; POSITION:absolute; left:50%; top:50%; width:600px; height:400px; margin-left:-300px; margin-top:-200px; border:1px solid #888; background-color:#edf; text-align:center">这是DIV登录框示例<br><a href="javascript:closeLogin();">关闭登录框</a></div>以上背景层的透明效果只适用于IE浏览器,如果要兼容所有浏览器的代码,可自己网上搜索,然后修改背景层的相应css代码即可。
原创粉丝点击