av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

JavaScript實現alert彈框效果

瀏覽:89日期:2023-06-15 08:41:28

本文實例為大家分享了JavaScript實現alert彈框的具體代碼,供大家參考,具體內容如下

因本人水平有限,不足之處還望大家指正。先上圖:

JavaScript實現alert彈框效果

為什么會出現這個需求?瀏覽器自帶的alert不好用嗎?

自帶的alert在不同的瀏覽器是有差異的,而且樣式也不美觀,用戶體驗度不是很好。所以我們要自己寫一個alert彈框,這樣我們就可以按照我們自己的需求,把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')); } }}

以下是具體要用時的代碼:

<!DOCTYPE HTML><html> <head> <meta http-equiv='content-type' content='text/html; charset=utf-8'> <title>Study</title> </head> <script type='text/javascript' charset='utf-8' src='http://www.4tl426be.cn/bcjs/alert.js'></script> <body> <script type='text/javascript' charset='utf-8'> myAlert.alertbox('這是自定義alert框'); </script> </body></html>

用法很簡單,引入alert.js文件,要用時直接myAlert.alertbox('內容');和使用alert一樣。

在這塊給大家提供個思路,供大家參考。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 成人爽a毛片一区二区免费 亚洲午夜在线观看 | 久久h| 性色av一区二区 | 国产农村妇女aaaaa视频 | 久久免费影院 | 日本精品视频在线 | 黄色成年人网站 | 色天堂视频 | 成人精品一区二区三区 | 亚洲激情成人 | 精品国产成人 | 美女视频一区二区 | 亚洲一区二区av | 日韩免费大片 | 国产一区二区网站 | 亚洲欧美国产精品 | 99久久久国产精品 | av黄色在线 | 黄色草逼视频 | 97精品在线| 黄色理论片| 午夜视频 | 免费视频一区 | 亚洲成人免费 | 成人午夜激情视频 | 97人人艹 | 国产黄色免费 | 久草新视频 | 久久亚洲一区二区 | 91麻豆精品 | 中文字幕一区二区三区乱码 | 久久精品美女 | 欧美成人精品一区二区三区在线看 | 午夜精品视频在线观看 | 黄色片网站在线观看 | 欧美日韩亚洲一区二区三区 | 国产精品免费一区二区 | 国产一级特黄aaa大片 | 日韩av资源 | 日韩福利在线 | 日日骚av |