廢話不多說(shuō)了,直接給大家貼代碼了,具體代碼如下所示:
<script> window.alert = alert; function alert(data) { var MainDiv = document.createElement("div"), p = document.createElement("p"), AllPage = document.createElement("div"), btn = document.createElement("div"), textNode = document.createTextNode(data ? data : ""), btnText = document.createTextNode("確定"); // 控制樣式 css(AllPage, { "position": "fixed", " _position": "absolute", " width": "100%", "height": "100%", "left": "0", "top": "0", "background": "rgba(0, 0, 0,0.5)", "-moz-opacity": "0.5", "filter": "alpha(opacity=50)", "z-index": "97", }); css(MainDiv, { "position": "fixed", "left": "0", "right": "0", "top": "30%", "width": "14rem", "height": "5rem", "padding-top":"0.5rem", "margin": "0 auto", "background-color": "white", "font-size": "0.75rem", "text-align": "center", "position": "relative", "border-radius": "5px 5px 5px 5px", }); css(btn, { "background": "#de241b", "color": "white", "width": "6rem", "margin-left": "4rem", "margin-bottom":"0.25rem", "height": "1.5rem", "border-radius": "5px 5px 5px 5px", "position": "absolute", "padding-top":"0.5rem", "bottom":"0", }) // 內(nèi)部結(jié)構(gòu)套入 p.appendChild(textNode); btn.appendChild(btnText); MainDiv.appendChild(p); MainDiv.appendChild(btn); AllPage.appendChild(MainDiv); // 整體顯示到頁(yè)面內(nèi) document.getElementsByTagName("body")[0].appendChild(AllPage); //禁止?jié)L動(dòng) $("body").on("touchmove", function (event) { event.preventDefault; }, false) // 確定綁定點(diǎn)擊事件刪除標(biāo)簽 btn.onclick = function () { AllPage.parentNode.removeChild(AllPage); //啟用滾動(dòng) $("body").off("touchmove"); } } function css(targetObj, cssObj) { var str = targetObj.getAttribute("style") ? targetObj.getAttribute("style") : ""; for (var i in cssObj) { str += i + ":" + cssObj[i] + ";"; } targetObj.style.cssText = str; } 以上所述是小編給大家介紹的使用JavaScript實(shí)現(xiàn)alert的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)錯(cuò)新站長(zhǎng)站網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選