<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>显示消息提示框</title>
<style>
.confirm .box{
width: 70%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 8px;
overflow: hidden;
text-align: center;
color: #333;
z-index: 999;
background: #fff;
display: flex;
flex-wrap: wrap;
font-weight: 500;
}
.confirm .box>div{
width: 100%;
}
.confirm .box .title{
padding-top: 10px;
}
.confirm .box .content{
color: #838383;
padding: 10px;
}
.confirm .box .btn{
display: flex;
justify-content: space-between;
border-top: 1px solid #E2E2E2;
}
.confirm .box .btn>div{
flex: 1;
padding: 10px 0px;
color: #1A73E8;
}
.confirm .box .btn div:nth-child(1){
border-right: 1px solid #E2E2E2;
}
.confirm .mask{
background: rgba(20, 20, 20, 0.8);
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: 1px solid #333;
}
</style>
</head>
<body>
<button id="pay">H5支付</button>
<!-- <div class="confirm" >
<div class="box">
<div class="title">提示</div>
<div class="content">确认要支付吗?</div>
<div class="btn">
<div>取消</div>
<div>确定</div>
</div>
</div>
<div class="mask"></div>
</div> -->
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
// 调用弹框
function showToast(content,res,err){
let html = $(`<div class="confirm">
<div class="box">
<div class="title">提示</div>
<div class="content">${content}</div>
<div class="btn">
<div>取消</div>
<div>确定</div>
</div>
</div>
<div class="mask"></div>
</div>`)
$("body").append(html)
$("body").on('click', '.btn',function(e){
let text = e.target.innerText
if(text == "确定"){
if ($.isFunction(res)) {
res()
}
}else{
if ($.isFunction(err)) {
err()
}
}
$(".confirm").remove()
})
}
$("#pay").click(function(){
showToast("确认要支付吗?",function(){
console.log("success")
},function(){
console.log("fail")
})
})
</script>
</body>
</html>
jQuery自定义信息提示框组件
最新推荐文章于 2023-04-11 08:47:57 发布