<!DOCTYPE html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title></title> <style type= "text/css" > * { box-sizing: border-box; } .clearfix:after { content: ‘ ‘ ; display: table; clear: both; } .clearfix { *zoom: 1; } div.hi-dialog-box { border: 1px #808080 solid; width: 350px; height: 200px; position: absolute; top: 200px; left: 40%; border-radius: 3px; } div.hi-dialog-box div.hi-dialog-title { border: 1px #808080 solid; margin: 1px; padding: 1px; background-color: #dedcdc; height: 14%; cursor: move; font-size: 20px; } div.hi-dialog-box div.hi-dialog-content { height: 65%; margin: 5px; overflow: auto; } div.hi-dialog-box div.hi-dialog-foot { margin: 1px; padding: 1px; height: 14%; } div.hi-dialog-box div.hi-dialog-foot input { float: right; margin-left: 5px; font-size: 16px; } </style> </head> <body> <input value= "对话框(确定)" onclick= "click1();" type= "button" /> <input value= "对话框(确定、取消)" onclick= "click2();" type= "button" /> <div class= "messg" style= "margin: 10px; color: red; font-size: 23px" ></div> <script src= "../../Scripts/jquery-1.8.2.js" ></script> <script type= "text/javascript" > var hiDialog = { init: function (title, messg, determineCallback, cancelCallback) { title = title || "系统提示" ; var determine = "" , cancel = "" ; if ( typeof (determineCallback) == "function" ) determine = ‘<input type="button" class="hi-dialog-determine" value="确定" />‘ ; if ( typeof (cancelCallback) == "function" ) cancel = ‘<input type="button" class="hi-dialog-cancel" value="取消" />‘ ; if (!$( "div.hi-dialog-box" ).length) { var hi_dialog_box = ‘<div class="hi-dialog-box clearfix">\ <div class="hi-dialog-title"></div>\ <div class="hi-dialog-content">\ </div>\ <div class="hi-dialog-foot">\ </div>\ </div>‘ ; $( "body" ).append(hi_dialog_box); } var $box = $( "div.hi-dialog-box" ); $box.find( "div.hi-dialog-title" ).html(title); $box.find( "div.hi-dialog-content" ).html(messg); $box.find( "div.hi-dialog-foot" ).html(determine + cancel); $( "div.hi-dialog-box" ).show(); $box.find( ".hi-dialog-determine" ).click( function () { determineCallback(); hiDialog.close(); }); $box.find( ".hi-dialog-cancel" ).click( function () { cancelCallback(); hiDialog.close(); }); //鼠标按下时 $( "div.hi-dialog-title" ).mousedown( function (event) { $( "html" ).unbind(); var click_clientX = event.clientX; var click_clientY = event.clientY; var dialogBox = $( this ).closest( "div.hi-dialog-box" ); var dialogBoxX = parseInt($(dialogBox).css( "left" )); var dialogBoxY = parseInt($(dialogBox).css( "top" )); //鼠标移动时 $( "html" ).mousemove(dialog_mousemove = function (event) { var top = event.clientY - click_clientY + dialogBoxY; var left = event.clientX - click_clientX + dialogBoxX; $(dialogBox).css({ "left" : left, "top" : top }); }); //鼠标按键松开时 $( "html" ).mouseup( function () { $( "html" ).unbind( "mousemove" , dialog_mousemove); }); }); }, close: function () { $( "div.hi-dialog-box" ).hide(); } } </script> <script type= "text/javascript" > function click1() { hiDialog.init( "系统提示!" , "测试" , function () { //点击确定后的回调执行 $( ".messg" ).text( "点击了确定" ); }); } function click2() { hiDialog.init( "系统对话框~~" , "什么乱七八糟的啊..." , function () { $( ".messg" ).text( "点击了确定~~~" ); }, function () { $( ".messg" ).text( "点击了取消~~" ); }); } </script> </body> </html> |
消息框
要求:自动定时关闭消息框、有消息分类(如:警告、错误、成功等)
画一个简单的模型框
1
2
3
4
|
<div class= "hi-message-box" > <img class= "hi-message-type" src= "" /> <span class= "hi-message-messg" >你不爱我了~~</span> </div> |
添上基本样式
1
2
3
4
5
6
7
8
9
10
11
12
|
<style type= "text/css" > div.hi-message-box { padding: 10px; padding-top: 15px; padding-bottom: 20px; background-color: #aee0c1; min-width: 200px; max-width: 500px; font-size: 19px; border-radius: 3px; } </style> |
效果图:
看上去是不是很简单呢?下面我们给它加上定时关闭消息功能。
定时关闭消息(表骂我,就是这么简单。我也想写复杂的。)
setTimeout(function () { $("div.hi-message-box").fadeOut("slow");}, 1200);
效果图:
加上消息类型(其实就是根据参数加不同的图片而已)
1
2
3
|
setTimeout( function () { $( "div.hi-message-box" ).fadeOut( "slow" ); }, 1200); |
效果图:
加上图标是不是更像那么回事了?
如上,我们同样需要稍微整理下实现代码:
效果图:
全部代码:(同样,消息框也只是进行了简单实现。还有太多没有考虑,如(参数定位消息框位置、设置定时关闭时间、多次触发消息框))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<!DOCTYPE html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title></title> <style type= "text/css" > * { box-sizing: border-box; } .clearfix:after { content: ‘ ‘ ; display: table; clear: both; } .clearfix { *zoom: 1; } div.hi-message-box { padding: 10px; padding-top: 15px; padding-bottom: 20px; background-color: #aee0c1; position: absolute; min-width: 200px; max-width: 500px; font-size: 19px; border-radius: 3px; top:200px; left:45%; } div.hi-message-box img { vertical-align: bottom; } </style> </head> <body> <input type= "button" onclick= "success();" value= "成功消息" /> <input type= "button" onclick= "error();" value= "失败消息" /> <input type= "button" onclick= "warn();" value= "警告消息" /> <script src= "../../Scripts/jquery-1.8.2.js" ></script> <script type= "text/javascript" > var hiMessageBox = { init: function (type, messg) { var hiMessageBox = ‘<div class="hi-message-box">\ <img class="hi-message-type" src="" />\ <span class="hi-message-messg"></span>\ </div>‘ ; if (!$( "div.hi-message-box" ).length) { $( "body" ).append(hiMessageBox); } var $box = $( "div.hi-message-box" ); $box.find( ".hi-message-messg" ).text(messg); switch (type) { case 0: //success 成功 $box.find( "img.hi-message-type" ).attr( "src" , "imgs/Tick_24px.png" ) break ; case 1: //warn 警告 $box.find( "img.hi-message-type" ).attr( "src" , "imgs/Warning_24px.png" ) break ; case 2: // $box.find( "img.hi-message-type" ).attr( "src" , "imgs/Delete_24px.png" ) break ; } $( "div.hi-message-box" ).fadeIn( "slow" ) setTimeout( function () { $( "div.hi-message-box" ).fadeOut( "slow" ); }, 1200); }, success: function (messg) { this .init(0, messg); }, warn: function (messg) { this .init(1, messg); }, error: function (messg) { this .init(2, messg); } }; </script> <script type= "text/javascript" > function success() { hiMessageBox.success( "成功" ); } function error() { hiMessageBox.error( "失败" ); } function warn() { hiMessageBox.warn( "警告" ); } </script> </body> </html> |
以上所述是基于基于.Net实现前端对话框和消息框的全部叙述,希望对大家有所帮助,如果大家想了解更多内容,敬请关注脚本之家!
您可能感兴趣的文章:
相关文章
- 2010-06-06Asp.net下用JQuery找出哪一个元素引起PostBack
- 2006-09-09ASP.NET技巧:请求网址并解析返回的html
- 2011-06-06从ASP.NET得到Microsoft Word文档的代码
- 2007-03-03relaxlife.net发布一个自己开发的中文分词程序
- 2013-03-03C#反射(Reflection)对类的属性get或set值实现思路
- 2012-05-05asp.net 简便无刷新文件上传系统
- 2013-06-06读取纯真IP数据库的公用组件接口QQWry.NET
- 2013-04-04Asp.net静态方法之Grid转DataTable方法实现步骤
- 2012-11-11asp.net中对象失去焦点时自动提交数据 V2
- 2013-10-10C#判断文件路径是否存在或者判断文件是否存在的方法
最新评论