手机重写alert方法(去除网址和关闭网页按钮)
js代碼
/*重寫alert方法*/window.alert = function(str){var alertFram = document.createElement("DIV");alertFram.id="alertFram";alertFram.style.position = "fixed";alertFram.style.width = "100%";alertFram.style.height = "100%";alertFram.style.top = "0";alertFram.style.textAlign = "center";alertFram.style.lineHeight = "150px";alertFram.style.zIndex = "300";alertFram.style.backgroundColor="rgba(0, 0, 0, 0.58)";alertFram.style.fontSize="12px";strHtml = '<ul class="alert_ul">';strHtml += '<li class="alert_content">'+str+'</li>';strHtml += '<li class="alert_btn-wrap"><a type="button" value="確定" οnclick="doOk()" class="alert_btn">確定</a></li>';strHtml += '</ul>';alertFram.innerHTML = strHtml;document.body.appendChild(alertFram);this.doOk = function(){alertFram.style.display = "none";}}css渲染
.alert_ul{list-style:none;margin:0px;padding:0px;width:70%;margin: auto;margin-top: 53%;} .alert_title{background:#F2F2F2;text-align:left;padding-left:20px;line-height:60px;border:1px solid #999;} .alert_content{background:#fff;text-align:center;height:80px;line-height:80px;} .alert_btn-wrap{background:#fff;text-align:center;height:30px;line-height:18px;} .alert_btn{cursor:pointer;color:#2bd00f;}使用方法:
加入css和js,直接編寫;
alert("推薦失敗,請重新操作。");
/*重寫alert方法*/ window.alert = function(str){ ? ? ? ?var alertFram = document.createElement("DIV"); ? ?alertFram.id="alertFram"; ? ?alertFram.style.position = "fixed"; ? ?alertFram.style.width = "100%"; ? ?alertFram.style.height = "100%"; ? ?alertFram.style.top = "0"; ? ?alertFram.style.textAlign = "center"; ? ?alertFram.style.lineHeight = "150px"; ? ?alertFram.style.zIndex = "300"; ? ?alertFram.style.backgroundColor="rgba(0, 0, 0, 0.58)"; ? ?alertFram.style.fontSize="12px"; ? ?strHtml = '<ul class="alert_ul">'; ? ?strHtml += '<li class="alert_content">'+str+'</li>'; ? ?strHtml += '<li class="alert_btn-wrap"><a type="button" value="確定" οnclick="doOk()" class="alert_btn">確定</a></li>'; ? ?strHtml += '</ul>'; ? ?alertFram.innerHTML = strHtml; ? ?document.body.appendChild(alertFram); ? ?this.doOk = function(){ ? ? ? ?alertFram.style.display = "none"; ? ?}}
轉載于:https://www.cnblogs.com/important/p/7656876.html
總結
以上是生活随笔為你收集整理的手机重写alert方法(去除网址和关闭网页按钮)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 封装fetch的使用(包含超时处理)
- 下一篇: 在studio中使用libsdl2.so