惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
V
Visual Studio Blog
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
K
Kaspersky official blog
博客园 - 叶小钗
月光博客
月光博客
S
Schneier on Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
量子位
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
P
Privacy & Cybersecurity Law Blog
Cyberwarzone
Cyberwarzone
S
Securelist
Hugging Face - Blog
Hugging Face - Blog
B
Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Vulnerabilities – Threatpost
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
V
V2EX
MongoDB | Blog
MongoDB | Blog
博客园_首页
Recorded Future
Recorded Future
酷 壳 – CoolShell
酷 壳 – CoolShell
F
Fortinet All Blogs
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Troy Hunt's Blog
罗磊的独立博客
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Proofpoint News Feed
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
O
OpenAI News
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
N
News | PayPal Newsroom
G
GRAHAM CLULEY
H
Hacker News: Front Page
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - Star.Stroll

【Chrome扩展】Reload image 重载图片 [原创]RegularJS [原创]虚拟化技术真的能让企业降低成本吗? [原创]纯Java获得本地MAC地址 [原创]GCC动态链接库的编译与使用简例 [原创]Cygwin的中文支持(解决乱码) [原创]程序员日志:自制随笔程序 [原创]程序员日志:程序员的快捷方式 [原创]Java Socket(套接字)自学笔记1 深入HashCode方法 JavaScript代码实例:拖动对象 Drag Object (兼容:IE、Firefox、Opera ... ) Tomcat中用web.xml控制Web应用详解(2) Tomcat中用web.xml控制Web应用详解(1) java.sql.ResultSet 新增、更新、刪除資料 [原创]一个简单例子解释 Java 工厂模式 [原创]Object.clone()的作用与用法 Java 范型编程 Singleton模式(单态模式) Builder模式
[原创]透明的DIV提示框(兼容IE与Firefox)
Star.Stroll · 2008-06-26 · via 博客园 - Star.Stroll

浏览器给我们提供了几种对话框,alert(),confirm()...这些对话框虽然易用但是同时有几个缺点:

(1)按钮数量与其上面显示的文字不可改变.
(2)对话框样式单调不好看.
(3)对话框内只能显示文字.

因为以上原因很多网站都选择使用Javascript+CSS编写自己的DIV对话框,DIV对话框不但好看而且能完成大部分的业务需求,于是我也开始试着编写这样的对话框,以下是我个人编写的一个DIV对话框例子:

<html>

<head>
<style>
body
{
    margin
:0px;
}
    
</style>
<title></title>
<script>

function DivAlert(messageDiv){
    
this.messageDIV=messageDiv;
    
//创建提示框底层 
    this.bottomDIV = document.createElement("div");
    
    
//获取body中间点
    var x=document.body.clientWidth/2,y=document.body.clientHeight/2;

    
//配置样式
    this.bottomDIV.style.opacity="0.50";
    
this.bottomDIV.style.filter="Alpha(opacity=50);";
    
this.bottomDIV.style.backgroundColor="#CCCCCC";
    
this.bottomDIV.style.height=
document.body.scrollHeight+"px";
    this.bottomDIV.style.width="100%";
    
this.bottomDIV.style.marginTop="0px";
    
this.bottomDIV.style.marginLeft="0px";
    
this.bottomDIV.style.position="absolute";
    
this.bottomDIV.style.top="0px";
    
this.bottomDIV.style.left="0px";
    
this.bottomDIV.style.zIndex=100;

    
//显示提示框
    this.show = function(){
        
//显示提示框底层 
          document.body.appendChild(this.bottomDIV);
        
//显示messageDIV
        document.body.appendChild(this.messageDIV);
        
//把messageDIV定位到body中间
        this.messageDIV.style.position="absolute";
        x
=x-this.messageDIV.clientWidth/2;
        y=y-this.messageDIV.clientHeight/2;
        this.messageDIV.style.top=y+"px";
        
this.messageDIV.style.left=x+"px";
        
this.messageDIV.style.zIndex=101;
      }

      
    
//移除提示框
      this.remove = function(){
          document.body.removeChild(
this.bottomDIV);
        document.body.removeChild(
this.messageDIV);
      }

}




//测试DivAlert对象
var dc;
function test(){
     
//创建提示框内容部分
     var d = document.createElement("div");
     d.style.width
="220px";
     d.style.height
="150px";
     d.style.backgroundColor
="#AA00CC";
     d.style.padding
="10px";

     
//向提示框内容部分画需要显示的信息
     d.innerHTML="Hello World<br/><input type=\"button\" style=\"color:#cc4044\" value=\"close this DivAlert\" onclick=\"test2()\"/>"
     
     
//实例化提示框
     dc = new DivAlert(d);
     
//显示提示框
     dc.show();
}


//提示框里的Button按钮点击事件
function test2(){
    
//移除对话框
    dc.remove();
}

</script>
</head>

<body>
<href="javascript:void(0)" onClick="test();">click</a>
</body>

</html>

运行效果:

点击弹出提示框