最近写了一个重构的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. 深入.NET和C#的小型汽车租赁系统的框架

    前言:写这个小型系统之前呢,我们应该要猜测可能要用到哪些知识点. 那么对于这个小型系统:主要用到了如下的知识:  封装,集合(ArrayList和HashTable)和泛型和非泛型集合(泛型:List ...

  2. jquery右下角自动弹出关闭层

    效果体验:http://keleyi.com/keleyi/phtml/jqtexiao/36.htm 右下角弹出层后,会在一定时间后自动隐藏.第一版本:http://www.cnblogs.com/ ...

  3. K近邻模型(k-NN)

    原理 K最近邻(k-Nearest Neighbor,KNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一.该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻 ...

  4. Introduction to Microsoft Dynamics 365 licensing

    Microsoft Dynamics 365 will be released on November 1. In preparation for that, Scott Guthrie hosted ...

  5. SharePoint 2016 图文安装教程

    前言 SharePoint 2016如约而至,之前也装过预览版,但是这次是正式版,还是分享一个完整的安装过程给大家,希望能给有需要的人有所帮助. 1.首先安装操作系统,我这里是Windows Serv ...

  6. iOS - Json解析精度丢失处理(NSString, Double, Float)

    开发中处理处理价格金额问题, 后台经常返回float类型, 打印或转成NSString都会有精度丢失问题, 因此使用系统自带的NSDecimalNumber做处理, 能解决这问题:经过测试其实系统NS ...

  7. 操作系统开发系列—1.HelloWorld ●

    org 07c00h ;伪指令,告诉编译器程序会被加载到7c00处 mov ax, cs mov ds, ax mov es, ax call DispStr ;调用显示字符串例程 jmp $ ;无限 ...

  8. python头部注释 vim添加头部注释

    1.先说说python和virtual python 一般环境下,python解释器会放在/usr/bin/ 下面,然后你执行python的时候就会运行了,但是如果没有在/usr/bin/下面的话,执 ...

  9. SQL Server解决孤立用户浅析

    孤立用户概念        所谓孤立用户即指在服务器实例上未定义或错误定义了其相应 SQL Server 登录名的数据库用户无法登录到实例. 这样的用户被称为此服务器实例上的数据库的"孤立用 ...

  10. 实战:考虑性能--Solr索引的schema设计

    从 high level 的角度来看,schema.xml 结果如下,这个例子虽然不是一个真实的XML,但是简洁明了的传达了shema的概念. <schema> <types> ...