<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script src="../js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="../js/bootstrap-typeahead.js" type="text/javascript"></script>
<link href="../css/bootstrap.min.css" rel="stylesheet"/>
<script src="../js/bootstrap.min.js" type="text/javascript"></script>
<script src="../js/bootstrap-select.js" type="text/javascript"></script>
<link href="../css/bootstrap-select.min.css" rel="stylesheet"/> <script type="text/javascript">
/*
用途描述:自定义的消息提示框和消息确认框,采用jquery的闭包方法实现,但必须依赖
与jQuery,否则没有效果。
使用说明:
alert框请调用:zdalert(title,top,width, message, function(ret))
confirm框请调用:zdconfirm(title,top,width, message, function(ret))
方法参数说明:
title:弹出框的显示标题;
top:弹出框位于当前窗体的高度,请填写整数值,使用的分数形式(_height - boxHeight) / top
width:弹出框的宽度,请填写px值。
message:弹出框显示的内容。
function:回调函数,需要执行的内容方法,参数ret有一个,为ture和false值*/ (function($) {
//声明闭包方法
$.alerts = {
alert: function(title,top,width, message, callback) {
if( title == null ) title = 'Alert';
$.alerts._show(title,top,width, message, null, 'alert', function() {
if( callback ) callback(result);
});
}, confirm: function(title, top,width,message, callback) {
if( title == null ) title = 'Confirm';
$.alerts._show(title, top,width,message, null, 'confirm', function(result) {
if( callback ) callback(result);
});
}, _show: function(title,top,width,msg, value, type, callback) { var _html = ""; _html += '<div id="mb_box"></div><div id="mb_con"><span id="mb_tit">' + title + '</span>';
_html += '<div id="mb_msg">' + msg + '</div><div id="mb_btnbox">';
if (type == "alert") {
_html += '<input id="mb_btn_ok" type="button" value="确定" />';
}
if (type == "confirm") {
_html += '<input id="mb_btn_ok" type="button" value="确定" />';
_html += '<input id="mb_btn_no" type="button" value="取消" />';
}
_html += '</div></div>'; //必须先将_html添加到body,再设置Css样式
$("body").append(_html); GenerateCss(top,width);
//判断是确认框还是提示框
switch( type ) {
case 'alert': $("#mb_btn_ok").click( function() {
$.alerts._hide();
callback(true);
});
$("#mb_btn_ok").focus().keypress( function(e) {
if( e.keyCode == 13 || e.keyCode == 27 ) $("#mb_btn_ok").trigger('click');
});
break;
case 'confirm': $("#mb_btn_ok").click( function() {
$.alerts._hide();
if( callback ) callback(true);
});
$("#mb_btn_no").click( function() {
$.alerts._hide();
if( callback ) callback(false);
});
$("#mb_btn_no").focus();
//键盘的按键快捷键
$("#mb_btn_ok, #mb_btn_no").keypress( function(e) {
//enter键
if( e.keyCode == 13 ) {$("#mb_btn_ok").trigger('click');}
//esc键
if( e.keyCode == 27 ){ $("#mb_btn_no").trigger('click');}
});
break; }
},
_hide: function() {
$("#mb_box,#mb_con").remove();
}
}
// 显示提示框,top,width:top窗体位置当前窗口的高低的百分比,必须填写整数;width窗体显示的宽度。
zdalert = function(title,top,width, message, callback) {
$.alerts.alert(title,top,width, message, callback);
}
//显示确认框,top,width:top窗体位置当前窗口的高低的百分比,必须填写整数;width窗体显示的宽度。
zdconfirm = function(title,top,width, message, callback) {
$.alerts.confirm(title,top,width, message, callback);
}; //生成Css
var GenerateCss = function (top,width) { $("#mb_box").css({ width: '100%', height: '100%', zIndex: '99999', position: 'fixed',
filter: 'Alpha(opacity=60)', backgroundColor: 'black', top: '0', left: '0', opacity: '0.6'
}); /*$("#mb_con").css({ zIndex: '999999', width: '350px', position: 'fixed',
backgroundColor: 'White', borderRadius: '15px'
});*/
//去掉边框的圆
$("#mb_con").css({ zIndex: '999999', width:width, position: 'fixed',
backgroundColor: 'White'
}); $("#mb_tit").css({ display: 'block', fontSize: '14px', color: 'white', padding: '10px 15px',
backgroundColor: '#31B0D5', borderRadius: '0 0 0 0',
borderBottom: '3px solid #999', fontWeight: 'bold'
}); $("#mb_msg").css({ padding: '20px', lineHeight: '20px',
borderBottom: '1px dashed #DDD', fontSize: '16px',backgroundColor:'#FCFCFC'
}); $("#mb_ico").css({ display: 'block', position: 'absolute', right: '10px', top: '9px',
border: '1px solid Gray', width: '18px', height: '18px', textAlign: 'center',
lineHeight: '16px', cursor: 'pointer', borderRadius: '12px', fontFamily: '微软雅黑'
}); $("#mb_btnbox").css({ margin: '15px 0 10px 0', textAlign: 'center' });
$("#mb_btn_ok,#mb_btn_no").css({ width: '85px', height: '30px', color: 'white', border: 'none' });
$("#mb_btn_ok").css({ backgroundColor: '#168bbb' });
$("#mb_btn_no").css({ backgroundColor: '#168bbb', marginLeft: '20px' }); //右上角关闭按钮hover样式
$("#mb_ico").hover(function () {
$(this).css({ backgroundColor: 'Red', color: 'White' });
}, function () {
$(this).css({ backgroundColor: '#DDD', color: 'black' });
}); var _widht = document.documentElement.clientWidth; //屏幕宽
var _height = document.documentElement.clientHeight; //屏幕高 var boxWidth = $("#mb_con").width();
var boxHeight = $("#mb_con").height(); //让提示框居中
$("#mb_con").css({ top: (_height - boxHeight) / top + "px", left: (_widht - boxWidth) / 2 + "px" });
} })(jQuery);
</script> <body>
<input id="add" type="button" value="添加" />
<input id="update" type="button" value="修改" /> <script type="text/javascript"> $("#add").bind("click", function () {
// $.MsgBox.Alert("消息", "哈哈,添加成功!"); zdalert('系统提示',3,"350px",'请输入正确数值',function(){ //要回调的方法
window.location.href="http://www.baidu.com"}); }); //也可以传方法名 test
$("#update").bind("click", function () { // $.MsgBox.Confirm("温馨提示", "确定要进行修改吗?", test); zdconfirm('系统确认框',6,"350px",'你确认提交该条数据吗',function(r){
if(r)
{
//...点确定之后执行的内容 window.location.href="http://www.baidu.com"
}
}); }); </script> </body>
</html>

jquery实现自定义弹出框的更多相关文章

  1. 弹出框一 之 基于bootstrap和jquery的自定义弹出框

    (function ($) { window.Ewin = function () { var html = '<div id="[Id]" class="moda ...

  2. .NET MVC 学习笔记(四)— 基于Bootstarp自定义弹出框

    .NET MVC 学习笔记(四)—— 基于Bootstarp自定义弹出框 转载自:https://www.cnblogs.com/nele/p/5327380.html (function ($) { ...

  3. js自定义弹出框

    js自定义弹出框: 代码如下 <html> <head><title>自定义弹出对话框</title> <style type ="te ...

  4. android自定义弹出框样式实现

    前言: 做项目时,感觉Android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个. 废话不说先上图片: 实现机制 1.先自定义一个弹出框的样式 2.自己实现CustomD ...

  5. react native仿微信性别选择-自定义弹出框

    简述 要实现微信性别选择需要使用两部分的技术: 第一.是自定义弹出框: 第二.单选框控件使用: 效果 实现 一.配置弹出框 弹出框用的是:react-native-popup-dialog(Git地址 ...

  6. bootstrap插件bootbox参数和自定义弹出框宽度设置

    插件官方地址:http://bootboxjs.com/ alert: 1 bootbox.alert("Hello world!", function() {}); dialog ...

  7. jquery的Layer弹出框操作

    在layer中,我们要先获取窗口的索引,然后再进行操作. var index = parent.layer.getFrameIndex(window.name); //获取窗口索引 $("# ...

  8. 自定义弹出框基于zepto 记得引入zepto

    html <!DOCTYPE html> <html> <meta charset="utf-8"> <title></tit ...

  9. android 自定义弹出框AlertDialog ,很炫的哦

      于是就小小的模仿了下自己写了这个这样的效果,主要代码如下:dlg = new AlertDialog.Builder(context).create();dlg.show();dlg.getWin ...

随机推荐

  1. python 的三元表达式

    python中的三目运算符不像其他语言 其他的一般都是 判定条件?为真时的结果:为假时的结果 如 result=5>3?1:0 这个输出1,但没有什么意义,仅仅是一个例子. 而在python中的 ...

  2. 浅析Apache中RewriteCond规则参数的详细介绍

    RewriteCond就像我们程序中的if语句一样,表示如果符合某个或某几个条件则执行RewriteCond下面紧邻的RewriteRule语句,这就是RewriteCond最原始.基础的功能,为了方 ...

  3. 使用ffmpeg下载m3u8流媒体

    安装 编译好的windows可用版本的下载地址(官网中可以连接到这个网站,和官方网站保持同步): http://ffmpeg.zeranoe.com/builds/ 或者: 百度网盘https://p ...

  4. 打造自己的LINQ Provider(上):Expression Tree揭秘

    概述 在.NET Framework 3.5中提供了LINQ 支持后,LINQ就以其强大而优雅的编程方式赢得了开发人员的喜爱,而各种LINQ Provider更是满天飞,如LINQ to NHiber ...

  5. jquery插件2

    1.很全,好用的jquery插件库:http://www.jq22.com/ 2.素材:http://www.sucaijiayuan.com/ 3.不错:http://www.helloweba.c ...

  6. 仿百度壁纸client(五)——实现搜索动画GestureDetector手势识别,动态更新搜索keyword

    仿百度壁纸client(五)--实现搜索动画GestureDetector手势识别,动态更新搜索关键字 百度壁纸系列 仿百度壁纸client(一)--主框架搭建,自己定义Tab + ViewPager ...

  7. 通过eclipse.ini修改Eclipse加载jdk的路径

    这里直接把在网上的找到的答案记录下来,原文地址:http://www.oschina.net/question/109676_15561: 如果出现 启动 Eclipse 弹出“Failed to l ...

  8. 重载(overload)、覆盖(override)和隐藏(hide)

    写正题之前,先给出几个关键字的中英文对照,重载(overload),覆盖(override),隐藏(hide).在早期的C++书籍中,可能翻译的人不熟悉专业用语(也不能怪他们,他们不是搞计算机编程的, ...

  9. A/B(逆元)

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  10. 关于mac上的maven

    1 mac上的maven的JAVA_HOME mac上maven的JAVA_HOME不是环境变量的JAVA_HOME,而是~/.mavenrc中的JAVA_HOME. 2 彻底解决mac上使用mvn ...