参考:https://www.cnblogs.com/st-leslie/articles/5279864.html

把window.alert=function(){}指向新的方法,即相当于重写

window.alert = function(str)
{
var shield = document.createElement("DIV");
shield.id = "shield";
shield.style.position = "fixed";
shield.style.left = "0px";
shield.style.top = "0px";
shield.style.width = "100%";
shield.style.height = document.body.scrollHeight+"px";
//弹出对话框时的背景颜色
shield.style.background = "#fff";
shield.style.textAlign = "center";
shield.style.zIndex = "299";
//背景透明 IE有效
//shield.style.filter = "alpha(opacity=0)";
var alertFram = document.createElement("DIV");
alertFram.id="alertFram";
alertFram.style.position = "absolute";
alertFram.style.left = "50%";
alertFram.style.top = "50%";
// alertFram.style.marginLeft = "-50%";
// alertFram.style.marginTop = "-50%";
alertFram.style.transform="translate(-50%,-50%)"
alertFram.style.width = "80%";
alertFram.style.background = "#ff0000";
alertFram.style.textAlign = "center";
alertFram.style.zIndex = "300";
strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
strHtml += " <li style=\"background:#DD828D;text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid #F9CADE;\">[自定义提示]</li>\n";
strHtml += " <li style=\"background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1px solid #F9CADE;border-right:1px solid #F9CADE;\">"+str+"</li>\n";
strHtml += " <li style=\"background:#FDEEF4;text-align:center;font-weight:bold;height:25px;line-height:25px; border:1px solid #F9CADE;\"><input type=\"button\" value=\"确 定\" onclick=\"doOk()\" /></li>\n";
strHtml += "</ul>\n";
alertFram.innerHTML = strHtml;
document.body.appendChild(alertFram);
document.body.appendChild(shield);
//var ad = setInterval("doAlpha()",5);
this.doOk = function(){
alertFram.style.display = "none";
shield.style.display = "none";
}
alertFram.focus();
document.body.onselectstart = function(){return false;};
}

自定义alert的更多相关文章

  1. 利用bootstrap的modal组件自定义alert,confirm和modal对话框

    由于浏览器提供的alert和confirm框体验不好,而且浏览器没有提供一个标准的以对话框的形式显示自定义HTML的弹框函数,所以很多项目都会自定义对话框组件.本篇文章介绍自己在项目中基于bootst ...

  2. JavaScript实现自定义alert弹框

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAh0AAAFkCAYAAACEpYlzAAAfj0lEQVR4nO3dC5BddZ0n8F93pxOQCO

  3. 原生js实现自定义alert风格和实现

    2018年6月29 最新更新 添加函数节流,解决多次点击问题,添加单例模式,提高代码性能. <!DOCTYPE html> <html lang="en"> ...

  4. ios UIWebView自定义Alert风格的弹框

    之前开发过一个App,因为公司之前写好了网页版的内容和安卓版本的App,我进去后老板要求我ios直接用网页的内容,而不需要自己再搭建框架.我一听,偷笑了,这不就是一个UIWebView吗?简单! 但是 ...

  5. 自定义alert和confirm

    var common = {}; common.showAlert = function (msg) { var html = "<div id='dialog_alert' clas ...

  6. 自定义alert窗口样式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 自定义alert弹框,title不显示域名

    问题: 系统默认的alert弹框的title会默认显示网页域名 解决办法: (修改弹框样式) (function() { window.alert = function(name) { $(" ...

  8. [Swift通天遁地]一、超级工具-(14)使用SweetAlert制作漂亮的自定义Alert窗口

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  9. 自定义alert弹框,title不显示域名(重写alert)

    问题: 系统默认的alert弹框的title会默认显示网页域名 解决办法: (修改弹框样式) (function() { window.alert = function(name) { $(" ...

随机推荐

  1. 【QSBOJ】字符串编辑

    题目链接:https://bbs.csdn.net/topics/390289884?page=1 AC代码: #include<bits/stdc++.h> using namespac ...

  2. springboot的maven多模块项目架构微服务搭建——构建多模块项目(依赖方式)

    总想对微服务架构做一个小小的总结,不知如何下手,最近觉得还是从搭建微服务的过程来入手,对于springboot的maven项目从构建多模块架构进而衍化为常用的微服务架构来做个记录吧. 首先,创建多个s ...

  3. sql 经纬度范围检索(谷歌方案)

    SELECT id, ( * acos ( //公里: 6371 英里: 3959 cos ( radians(78.3232) ) * cos( radians( 数据库纬度字段) ) * cos( ...

  4. Java集合基于JDK1.8的ArrayList源码分析

    本篇分析ArrayList的源码,在分析之前先跟大家谈一谈数组.数组可能是我们最早接触到的数据结构之一,它是在内存中划分出一块连续的地址空间用来进行元素的存储,由于它直接操作内存,所以数组的性能要比集 ...

  5. TP5分页函数paginate中的each()传参

    在使用each()时,each()里面只能使用局部变量,当使用外部变量时会报未定义变量的错误,但是有时候我们还必须使用外部变量,就需要想是时作用域的问题,但是如果使用 global 全局虽然不报错,但 ...

  6. 四、Vue过渡与动画、过渡css类名、自定义指定、过滤器

    一.过渡 动画 1.1简单的过渡动画使用 parent.vue [0]定义一个待显示的数据 [1]定义一个显示隐藏flag [2]使用动画过滤标签,name用来连接style样式:v-show用来控制 ...

  7. 禁用u盘再启用

    将u盘量产为CDROM后,刷入ISO后需要重新插拔u盘才能访问新内容.此文展示的代码可以实现模拟这种行为,免插拔使windows重新读取cdrom. 网上参考资料有限,自行试验了很多种方法,终于成功了 ...

  8. C++面试常见问题——07容器和迭代器

    容器和迭代器 vector.list.deque #include<iostream> #include<vector> #include<deque> #incl ...

  9. spring boot 使用swagger

    在pom.xml中添加maven依赖 <dependency> <groupId>io.springfox</groupId> <artifactId> ...

  10. Mysql 存储过程造测试数据

    1.Mysql 存储过程造测试数据 -- 创建一个用户表 CREATE TABLE `sys_user` ( -- `id` CHAR (32) NOT NULL DEFAULT '' COMMENT ...