最近写了一个重构的alert,confirm控件,调用时直接使用alert,confirm即可

//调用方法

alert("提示语")

window.confirm('你确定要删除该记录?',function(){
  //回调函数
})

css部分

引入我写的一个基础样式

<link href="http://120.26.59.104/base.css" rel="stylesheet" type="text/css" />
.tck-cover{ width:100%; height:100%; position: fixed; top:; left:; z-index:; background-color:rgba(0,0,0,0.6); display:none;}
.modal-wapper{ width:340px; padding:20px; position:fixed; top:-200%; left:50%; box-shadow:0 0 5px rgba(0,0,0,0.5); z-index:; background-color:#fff; border-radius:5px;}

html部分

在页面底部增加代码

<!-- alert弹框  -->
<div class="modal-wapper clearfix" id="alert">
<p class="align-right line30 clearfix"><span class="close">X</span></p>
<p class="text font14 line20 pad10TB"></p>
<p class="align-right top10"> <a href="javascript:void(0)" class="btns btns-blue btns-small btnsConfirm">确定</a>
</p>
</div>
<!-- confirm弹框 -->
<div class="modal-wapper clearfix" id="confirm">
<p class="align-right line30 clearfix"><span class="close">X</span></p>
<p class="text font14 line20 pad10TB"></p>
<p class="align-right top10">
<a href="javascript:void(0)" class="btns btns-blue btns-small btnsConfirm">确定</a>
<a href="javascript:void(0)" class="btns btns-grey btns-small btnsCancel left20">取消</a>
</p>
</div>

js部分

<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
//调用部分
window.alert = function (msg) {
modal.modal($("#alert"),$(".close,#alert .btnsConfirm"),function(){
$("#alert .text").html(msg);
})
};
window.confirm = function (msg,callBack) {
modal.modal($("#confirm"),$(".close,#confirm .btnsCancel"),function(){
$("#confirm .text").html(msg);
$("#confirm .btnsConfirm").on("click",function(){
callBack();
modal.hide($("#confirm"))
}); })
};
//模态对话框
var modal = {
modal:function(b,c,callback){
$(".modal-wapper").css({"top":"-200%"});
b.css({"margin-left":-b.width()/2})
b.animate({"top":"20%"},200);
$(".tck-cover").fadeIn();
if($(".tck-cover").length==0){
$("body").append('<div class="tck-cover"></div>');
$(".tck-cover").fadeIn();
};
$(document).on("click",".tck-cover",function(){
modal.hide(b);
})
if(c){
c.click(function(){
modal.hide(b);
});
}
if(callback){callback()}
},
hide:function(b){
b.animate({"top":"-200%"},200);
$(".tck-cover").fadeOut(200);
setTimeout(function(){$(".tck-cover").remove();},200)
}
};

重构alert,confirm的更多相关文章

  1. alert/confirm/prompt 处理

    webdriver 中处理JavaScript 所生成的alert.confirm 以及prompt 是很简单的.具体思路是使用switch_to_alert()方法定位到alert/confirm/ ...

  2. 在Android的webview中定做js的alert,confirm和prompt对话框的方法

    在Android的webview中定制js的alert,confirm和prompt对话框的方法 http://618119.com/archives/2010/12/20/199.html 1.首先 ...

  3. 转:python webdriver API 之alert/confirm/prompt 处理

    webdriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到 alert/conf ...

  4. selenium python (十一)alert/confirm/prompt的处理(js中的弹出框)

    webdriver中处理js所生成的alert.confirm以及prompt,采用switch_to_alert()方法定位到alert/confirm/prompt.然后使用text/accept ...

  5. Python脚本控制的WebDriver 常用操作 <二十二> 处理alert / confirm / prompt

    测试用例场景 webdriver中处理原生的js alert confirm 以及prompt是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confirm/prom ...

  6. Bootstrap Modal 框 alert confirm loading

    /** * Created by Administrator on 2016/5/4. */ /** * 模态窗口 */ window.Modal = { tpls:{ alert:'<div ...

  7. 开发中少不了的Fun -- 微信开发IOS端alert/confirm提示信息,去除网址(URL)的方法

    在微信公众号开发的时候在使用[alert/confirm]弹出提示或者警告信息的时候,[alert/confirm]会将该公众号的网址显示出来,这样很不美观.所以很多时候我们会选择去除那个网址提示内容 ...

  8. Fixed the bug:while running alert/confirm in javascript the chrome freezes

    显示高级设置... 系统  -> 使用硬件加速模式(如果可用) 操作系统如果不支持硬件加速,却启动此项,就悲催了.小伙伴们可别瞎点了,太吃亏. 现象alert/confirm一执行,chrome ...

  9. 去除移动端alert/confirm的网址(url)

    移动端的alert.confirm都会显示来源的url,影响体验 下面的代码将alert和confirm重写了一遍,可去除url  参考了网上代码,完善了confirm不同状态跳转   示例代码: & ...

  10. Java Selenium - 几种对话框处理Alert\confirm\prompt

    1. Alert , 先用常规办法定位到能触发alert的按钮 , 然后 Alert alert = driver.switchTo().alert(); alert.accept(); 如果aler ...

随机推荐

  1. Apache Lucene(全文检索引擎)—分词器

    目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 本项目Demo已上传GitHub,欢迎大家fork下载学习:https://gith ...

  2. Tomcat的下载和配置

    目录结构: // contents structure [-] 下载Tomcat 配置Tomcat 运行Tomcat 参考文章 下载Tomcat 读者可以到apache官网下载Tomcat.笔者下载的 ...

  3. Windows8.1下安装NoSQL-- mongodb安装使用

    1. 官方下载monodb:http://www.mongodb.org/downloads 现在最新版本3.0 2. 以下载Windows 64-bit为例官方最新版的没有分开, 32位和64位是应 ...

  4. #9.1课堂总结#JS基础(二)

    在程序语言中数组的重要性不言而喻,JavaScript中数组也是最常使用的对象之一,数组是值的有序集合,由于弱类型的原因,JavaScript中数组十分灵活.强大,不像是Java等强类型高级语言数组只 ...

  5. 你的USB设备还安全吗?USB的安全性已从根本上被打破!

    前言: USB设备使用方便,但也可能被用来携带恶意软件.病毒,感染计算机系统.通过禁用自动播放功能.杀毒软件查杀.不定期的对设备进行格式化等操作可以确保它是干净的.但它存在的安全问题要比我们想象的更深 ...

  6. Android-配置文件中设置“android:clickable="false"无效的原因及解决办法

    开发中遇到的问题:要实现一个button初始为不可点击,于是在配置文件中设置了android:clickable="false"运行后发现还是可以点击,于是写在了Activity中 ...

  7. mac brew & gcc安装

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ...

  8. Orchard中如何配置远端发布

    Orchard中默认安装是有Blog功能的.下面介绍如何配置Remote Blog Publishing功能,使用Windows Live Writer客户端发布博客. 一,开启Remote Blog ...

  9. .Net缓存管理框架CacheManager

    using System; using CacheManager.Core; namespace ConsoleApplication { class Program { static void Ma ...

  10. 代替Reflection(反射)的一些方法

    Reflection(反射)是深入学习.Net必须掌握的技能之一.最初学Reflection的时候,的确是被惊住了,原来还可以这样.只要给你一个Assembly, 你就能获取到其中所有的类型,根据类型 ...