JS通用弹窗,确定,取消可以回调方法。
2024-09-30 14:11:57
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
/* 首页弹出层 */
.confirm-tips{width:100%; height:100%; background:url(apher.png); position:fixed; top:0; z-index:999999999;overflow: auto;}
.confirm-tips-box{width:500px; height:334px; background:#FFF; position:absolute;top:25%;}
.confirm-tips-box h2{display:block; margin-top:50px; text-align:center; font-size:36px; font-weight:normal; color:#3881eb;}
.confirm-tips-box p{font-size:20px; color:#757c8a; text-align:center; display:block; margin-top:36px;}
.autobut a.submissionqx{display:inline-block; width:188px; height:60px; -moz-border-radius:6px; -webkit-border-radius:6px; border-radius:6px; border:1px solid #3881eb; text-align:center; line-height:60px; color:#3881eb; margin:0 auto; margin-top:60px; margin-bottom:50px; margin-left:45px; margin-right:30px;}
.autobut a.submission{display:inline-block; width:188px; height:60px; -moz-border-radius:6px; -webkit-border-radius:6px; border-radius:6px; background:#3881eb; text-align:center; line-height:60px; color:#FFF; margin:0 auto; margin-top:60px; margin-bottom:50px;}
</style>
</head>
<body>
<input id='alter_btn' type='button' value='弹窗确定取消按钮'/>
<span id='msg'></span>
<script>
/**
* 共用弹窗 确定 取消按钮
* eg: option = {
* title:'标题',
* msg:'内容',
* confirm:function(){
* 点击确定执行的方法
* },
* cancel:function(){
* 点击取消执行的方法
* }
* }
* eg: $.confirm_tips(option);
* @param obj
*/
$.confirm_tips = function(obj){
if(obj && obj.msg != ''){
if(!obj.title){
obj.title = '系统提示';
}
var left = parseFloat(($(document).width()-500)/2);
var tips_html = '<div class="confirm-tips confirm-tips-common" >' +
'<div class="confirm-tips-box" style="left:'+left+'px;">\n' +
' <h2>'+obj.title+'</h2>\n' +
' <p style="padding: 0 15px">'+obj.msg+'</p>\n' +
' <div class="autobut">\n' +
' <a href="javascript:;" class="submissionqx confirm-tips-cancelbtn">取消</a>\n' +
' <a href="javascript:;" class="submission confirm-tips-confirmbtn">确定</a>\n' +
' </div>\n' +
' </div></div>';
if($('.confirm-tips-common').length <= 0){
$('body').append(tips_html);
}
$('.confirm-tips-confirmbtn').click(function(){
if(obj.confirm){
obj.confirm();
}
$('.confirm-tips-common').remove();
$('.confirm-tips-confirmbtn').unbind();
})
$('.confirm-tips-cancelbtn').click(function(){
if(obj.cancel){
obj.cancel();
}
$('.confirm-tips-common').remove();
$('.confirm-tips-cancelbtn').unbind();
})
}
} $('#alter_btn').click(function(){
var option = {
title:'标题',
msg:'内容',
confirm:function(){
$('#msg').text('确定');
},
cancel:function(){
$('#msg').text('取消');
}
};
$.confirm_tips(option);
})
</script>
</body>
</html>
最新文章
- SAP CRM 使用Javascript触发SAP Server Event
- hadoop fs -ls no such file or directory
- C#监控USB接口
- php setcookie(name, value, expires, path, domain, secure) 参数详解
- IE浏览器的兼容模式代码细节解读
- 九、Socket之TCP编程
- YII 集成jquery
- 6.0RMB MP3所看到的……
- Java-继承的应用
- React与Preact差异之 -- setState
- 3分钟利用TurnipBit制作电子时钟
- Mybatis源码之Statement处理器BaseStatementHandler(二)
- ArrayList的ConcurrentModificationException异常和多线程下的异常
- 【转载】C#工具类:FTP操作辅助类FTPHelper
- 记一次AngularJs 路由 $stateChangeStart不起作用(细节决定成败)
- JQuery基本知识汇总;JQuery常用方法;浅入了解JQuery
- webpack 开发环境与生成环境的 配置
- 《Head First 设计模式》[02] 观察者模式
- Django xadmin引入DjangoUeditor
- 【IntelliJ 】IntelliJ IDEA 2017激活码