html
<div id="alertWin" style="display: none;">
<div class="alertCloser cssAlertCloser">
</div>
<div style="position:absolute;left:50%;top:50%;width:5px;height:5px;z-index: 21;">
<div class="alertContent cssAlertContent">
<div class="h1 title">提示:</div>
<div id="alertWin-content"></div>
<div id="alertWin-oper" style="text-align: center">
<div onclick="closeAlert();">关闭</div>
</div>
</div>
</div>
</div>
js
function closeAlert(){
document.getElementById("alertWin").style.display="none";
}
function openAlert(msg){
document.getElementById("alertWin-content").innerText=msg;
document.getElementById("alertWin-oper").style.display="block";
document.getElementById("alertWin").style.display="block";
}
function showProcess(){
document.getElementById("alertWin-content").innerText='';
document.getElementById("alertWin-oper").style.display="none";
document.getElementById("alertWin").style.display="block";
}
function setAlertMsg(msg){
document.getElementById("alertWin-content").innerText=msg;
}
css
#alertWin {
font-size: 16px;
}
#alertWin .centerPoint {
position: absolute;
left: 50%;
top: 50%;
width: 5px;
height: 5px;
z-index: 21;
}
#alertWin .cssAlertCloser {
height: 100%;
position: fixed;
top: 0px;
left: 0px;
right: 0px;
z-index: 20;
opacity: 0.3;
background-color: rgb(13, 13, 13);
}
#alertWin .cssAlertContent {
float: left;
width: 300px;
height: 160px;
margin-left: -150px;
margin-top: -100px;
background-color: white;
border-radius: 8px;
}
#alertWin .cssAlertContent .title {
height: 40px;
line-height: 50px;
border-bottom: 1px solid #f1f2f6;
padding-left: 15px;
color: #9b9ba6
}
#alertWin-content {
height: 50px;
color: rgb(118, 124, 140);
padding: 10px 10px;
}
#alertWin-oper{
text-align: center;
}
#alertWin-oper > div {
display: inline-block;
width: 150px;
height: 25px;
padding-top: 3px;
font-size: 14px;
color: white;
border-radius: 5px;
background-color: rgb(255, 104, 102);
}
综合方法
function openAlert(msg){
if($("#alertWin").length>0){
$("#alertWin").remove();
}
var html='<div id="alertWin"><div class="alertCloser cssAlertCloser" style="display: block;"></div>' +
'<div class="centerPoint"><div class="alertContent cssAlertContent"><div class="h1 title">提示:</div>' +
'<div id="alertWin-content">'+msg+'</div><div id="alertWin-oper"><div>关闭</div></div></div></div></div>';
$("body").append(html);
$("#alertWin .alertCloser").on("touchstart",function (e) {
// 判断默认行为是否可以被禁用
if (e.cancelable) {
// 判断默认行为是否已经被禁用
if (!e.defaultPrevented) {
e.preventDefault();
}
}
}).on("touchend",function (e) {
$("#alertWin").remove();
});
$("#alertWin-oper>div").on("touchstart",function (e) {
// 判断默认行为是否可以被禁用
if (e.cancelable) {
// 判断默认行为是否已经被禁用
if (!e.defaultPrevented) {
e.preventDefault();
}
}
}).on("touchend",function (e) {
$("#alertWin").remove();
});
}