JS使用alert如何實現一個彈框效果?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
具體內容如下
先上圖:
alert.js代碼:
var myAlert = { alertbox : function(alertContent){ var windowWidth = window.innerWidth; windowHeight = window.innerHeight; alertContainer = document.createElement("div"); alertContainer.id = "myAlertBox"; alertContainer.style.cssText="position:absolute;left:0px;top:0px;width:100%;z-index:9999;"; alertContainer.style.height = windowHeight+"px"; alertOpacity = document.createElement("div"); alertOpacity.style.cssText="position:absolute;left:0px;top:0px;width:100%;background:#000;opacity:0.5;z-index:9999;"; alertOpacity.style.height = windowHeight+"px"; alertContainer.appendChild(alertOpacity) alertMainBox = document.createElement("div"); alertMainBox.style.cssText="position:absolute;width:200px;height:200px;line-height:200px;text-align:center;background:green;z-index:10000;" alertMainBoxLeft = (windowWidth-200)/2; alertMainBoxTop = (windowHeight-200)/2; alertMainBox.style.left = alertMainBoxLeft+"px"; alertMainBox.style.top = alertMainBoxTop+"px"; alertMainBox.innerHTML = alertContent; alertContainer.appendChild(alertMainBox); alertClose = document.createElement("div"); alertClose.id = "closeBox"; alertClose.style.cssText = "position:absolute;right:0px;top:0px;width:30px;height:30px;background:red;cursor:pointer"; alertMainBox.appendChild(alertClose); document.body.appendChild(alertContainer); closeButton = document.getElementById("closeBox"); console.log(closeButton) closeButton.onclick = function(){ document.body.removeChild(document.getElementById("myAlertBox")); } } }
文章題目:JS使用alert如何實現一個彈框效果-創新互聯
標題路徑:http://vcdvsql.cn/article0/eieio.html
成都網站建設公司_創新互聯,為您提供網頁設計公司、網站維護、定制開發、面包屑導航、品牌網站設計、動態網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯