<!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. 李洪强经典面试题40-可能碰到的iOS笔试面试题-C语言

    可能碰到的iOS笔试面试题(4)--C语言 可能碰到的iOS笔试面试题(4)--C语言 C语言,开发的基础功底,iOS很多高级应用都要和C语言打交道,所以,C语言在iOS开发中的重要性,你懂的.里面的 ...

  2. freemarker在xml文件中遍历list数据

    delete   from pub_channelpackage   where channelcode = :channelcode   and channeltype = :channeltype ...

  3. [译]GLUT教程 - 改变窗体大小

    Lighthouse3d.com >> GLUT Tutorial >> Basics >> Resizing the Window 上一章的例子创建了两个窗体,命 ...

  4. Unity UGUI——提供可视功能的UI组件(Text)

    基本属性介绍 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTXJfQUhhbw==/font/5a6L5L2T/fontsize/400/fill/I0J ...

  5. 并行归并排序——MPI

    并行归并排序在程序开始时,会将n/comm_comm个键值分配给每个进程,程序结束时,所有的键值会按顺序存储在进程0中.为了做到这点,它使用了树形结构通信模式.当进程接收到另一个进程的键值时,它将该键 ...

  6. android中实现毛笔效果(View 中画图)

    近期有一个项目设计一个APP实现通过触摸屏实现毛笔写字效果.传统的绘画板程序直接通过Path的moveTo和LineTo便可实现简单的线条绘画程序.然而要达到毛笔的笔锋效果则须要更为具体点的设计.我的 ...

  7. html5小趣味知识点系列(一)autofocus

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

  8. Netty 源码(ChannelHandler 死磕)

    精进篇:netty源码死磕5  - 揭开 ChannelHandler 的神秘面纱 目录 1. 前言 2. Handler在经典Reactor中的角色 3. Handler在Netty中的坐标位置 4 ...

  9. 浅谈公平组合游戏IGC

    浅谈公平组合游戏IGC IGC简介 一个游戏满足以下条件时被叫做IGC游戏 (前面三个字是自己YY的,不必在意) 竞争性:两名玩家交替行动. 公平性:游戏进程的任意时刻,可以执行的操作和操作者本人无关 ...

  10. Django之stark组件的使用和总结

    Stark组件的使用 组件的字段 list_display=[] 需要显示的字段 list_display_links=[] #需要链接编辑字段 Stark_Model_Form=[] #设置Mode ...