自定义弹窗提示

html:

复制代码
 1     <!--弹出窗-->
 2     <div id="popup">
 3         <div class="popup_cont">
 4 
 5             <div class="title" style="height:40px;background-color:#32aadf;">
 6                 <span style="font-size:16px; color:white;display:inline-block; margin-top:8px; margin-left:10px;">提示</span>
 7                 <img id="img_close" data-text="close" data-operation="nothing" src="Images/close.png" style=" cursor:pointer; margin-top: 8px; margin-left: 318px; vertical-align: top;" />
 8             </div>
 9 
10             <div class="content" id="prompt_content" style="font-size:16px; text-align:center; padding:50px 10px;">
11                 <!--提示内容 提示内容 提示内容 提示内容-->
12             </div>
13 
14             <div class="operation" style="height: 40px; background-color: #cbcbcc; text-align: center; vertical-align: middle">
15                 <input class="confirm" id="popup_confirm" data-text="confirm" data-val="0" data-operation="nothing" type="button" style="margin:5px 10px; border-radius: 5px; padding: 3px 15px; color: white; background-color: #289fd2; font-size: 16px;  border: 0px solid #00A1E0; cursor: pointer; " value="确定" />
16                 <input class="cancel" id="popup_cancel" data-text="cancel"  data-operation="nothing" type="button" style="margin:5px 10px; border-radius: 5px; padding: 3px 15px; color: white; background-color: #a3a3a3; font-size: 16px;  border: 0px solid #00A1E0; cursor: pointer; " value="取消" />
17             </div>
18 
19         </div>
20     </div>
View Code
复制代码

 

css:

复制代码
 1 #popup {
 2     width: 100%;
 3     height: 100%;
 4     background-color: rgba(0, 0, 0, 0.6);
 5     opacity: 1;
 6     position: fixed;
 7     left: 0px;
 8     top: 0px;
 9     display: none;
10     z-index:100;
11 }
12 
13 #popup .popup_cont {
14     background: rgba(255, 255, 255, 0) none repeat scroll 0 0;
15     background-color: white;
16     height: 200px;
17     width: 400px;
18     margin: auto;
19     position: absolute;
20     top: 0;
21     left: 0;
22     bottom: 0;
23     right: 0;
24 }
View Code
复制代码

 

js调用方法(在iframe子页面调用的):

复制代码
 1 //弹出消息对象
 2 var objPopupMsg = {
 3 
 4     //确认框
 5     //msg:弹出消息
 6     //operation操作程序标识  无则不填 不填则默认为nothing 该值传过来后存在确认按钮的data-operation中
 7     //val 附加值  用于传参  默认为0 该值传过来后存在确认按钮的data-val中
 8     Confirm: function (msg, operation, val) {
 9         operation = objValidate.NotNull(operation) ? operation : "nothing";
10         val = objValidate.NotNull(val) ? val : "0";
11         $("#popup_confirm", window.parent.document).data("operation", operation).data("val", val);
12             $("#prompt_content", window.parent.document).text(msg);
13             $("#popup_cancel", window.parent.document).show();
14             $("#popup", window.parent.document).show();
15 
16     },
17 
18     //警告框
19     //msg:弹出消息
20     Alert: function (msg) {
21     
22             $("#prompt_content", window.parent.document).text(msg);
23             $("#popup_cancel", window.parent.document).hide();
24             $("#popup", window.parent.document).show();
25         
26     },
27 
28     //确定或取消返回值代码
29     ReturnVal: function () {
30         
31         //使用一下代码做处理获取弹出返回值
32 
33         ////关闭确定取消弹窗
34         $("#popup_confirm,#popup_cancel", window.parent.document).click(function () {
35             
36             //关闭弹窗
37             $("#popup", window.parent.document).hide();
38 
39 
40             //close confirm cancel  为区分点击的是关闭 确认 还是取消
41             var _text = $(this).data("text");
42 
43             //默认为nothing表示无操作 为区分同一页面有多个确认框 点击各个确认框所做出不同的处理 
44             //var _operation = $(this).data("operation");
45 
46             //附加值  用于传参  
47             //val只有点击确定按钮时才有 关闭 取消按钮没有
48             //var _val = $(this).data("val");
49 
50         });
51 
52 
53     }
54 
55 };
View Code
复制代码

 

js调用方法(当前页调用简单示例):

复制代码
1       //关闭弹窗
2             $("#img_close").click(function () {
3                 $("#popup").hide();
4             });
View Code
复制代码

 

posted @   妖狐鬼魅  阅读(119)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示