改写系统alert的弹出浮层的JS

//改写alert  
window.alert = function(txt)  
{  
    var borderColor = "#999";
    var title = "[月小升博客提示]";
    var shield = document.createElement("DIV");  
    shield.id = "shield";  
    shield.style.position = "absolute";  
    shield.style.left = "0px";  
    shield.style.top = "0px";  
    shield.style.width = "100%";  
    shield.style.height = document.body.scrollHeight+"px";  
    shield.style.background = "#333";  
    shield.style.textAlign = "center";  
    shield.style.zIndex = "10000";  
    shield.style.filter = "alpha(opacity=0)";  
    var alertFram = document.createElement("DIV");  
    alertFram.id="alertFram";  
    alertFram.style.position = "absolute";  
    alertFram.style.left = "50%";  
    alertFram.style.top = "50%";  
    alertFram.style.marginLeft = "-225px";  
    alertFram.style.marginTop = "-75px";  
    alertFram.style.width = "450px";  
    alertFram.style.height = "150px";  
    alertFram.style.background = "#ccc";  
    alertFram.style.textAlign = "center";  
    alertFram.style.lineHeight = "150px";  
    alertFram.style.zIndex = "10001";  
    strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";  
    strHtml += " <li style=\"background:"+borderColor+";text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid "+borderColor+";\">"+title+"</li>\n";  
    strHtml += " <li style=\"background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1px solid #ccc;border-right:1px solid #ccc;\">"+txt+"</li>\n";  
    strHtml += " <li style=\"background:"+borderColor+";text-align:center;font-weight:bold;height:25px;line-height:25px; border:1px solid "+borderColor+";\"><input type=\"button\" value=\"确 定\" onclick=\"doOk()\" /></li>\n";  
    strHtml += "</ul>\n";  
    alertFram.innerHTML = strHtml;  
    document.body.appendChild(alertFram);  
    document.body.appendChild(shield);  
    var c = 0;  
    this.doAlpha = function(){  
        if (c++ > 20){clearInterval(ad);return 0;}  
        shield.style.filter = "alpha(opacity="+c+");";  
    }  
    var ad = setInterval("doAlpha()",5);  
    this.doOk = function(){  
        alertFram.style.display = "none";  
        shield.style.display = "none";  
    }  
    alertFram.focus();  
    document.body.onselectstart = function(){return false;};  
}

调用页面改写系统的alert

<meta charset="UTF-8">
 
<script src="alert.js"></script>
 
<script>  
function chkpwd(){  
    if(document.getElementById('title').value==""){  
    alert('姓名不能为空');  
    return false;  
    }else if(document.getElementById('up_changeimg').value==""){  
    alert('图片上传不能为空');  
    return false;  
    }  
}  
</script>  
 
<form action="http://192.168.0.11/search" enctype="multipart/form-data" method="post" name="form_img" id="form_img" onsubmit="return chkpwd();">  
 
姓名:<input type="text" name="title" id="title"  value="" class="grsz_wek qianming biankuang"/>  
 
<input type="submit" name="savesubmit" id="savesubmit" class="bar" value="搜索"/>  
 
</form>

效果


This entry was posted in WEB前端 and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/js-alert-change-system/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

  

About Me

静水流深,水滴石穿