用JS怎样做一个简易的消息提示框?
Admin 2021-10-25 群英技术资讯 1579 次浏览
今天给大家分享的是用JS实现一个简易的消息提示框的内容,小编觉得比较实用,对新手学习JavaScript有一定的参考价值,实现效果及代码如下,感兴趣的朋友就继续往下看吧。
效果图
上代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <style> .popupStyle { display: none; width: 160px; background-color: rgb(85, 85, 85); color: #fff; text-align: center; border-radius: 6px; padding: 8px 0; position: fixed; z-index: 1; top: 2%; left: 50%; margin-left: -80px; } .popupStyle::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent; } </style> <body style="text-align:center"> <h2 style="margin-top: 100px;">弹窗</h2> <div style="text-align: center;"> <a href="#" onclick="handleMsg(msg)">点我有弹窗!</a> <a href="#" onclick="handleDomMsg(domMsg)">点我有弹窗!</a> </div> <span class="popupStyle" id="popupMsg">提示信息!</span> <script> const msg = "我是样式弹窗"; const domMsg = "我是DOM弹窗"; // 样式弹窗 function handleMsg(message) { const popup = document.getElementById("popupMsg"); popup.innerHTML = message || "Hello, World"; popup.style.display="block"; setTimeout(() => { popup.style.display="none" }, 1000); } // DOM 弹窗 function handleDomMsg(message) { const div = document.createElement("div"); document.body.appendChild(div); div.innerHTML = message || "this is a Message"; div.className = "popupStyle"; div.style.display = "block"; setTimeout(() => { div.remove(); }, 1000); } </script> </body> </html>
以上就是关于用JS实现简易的消息提示框的代码,需要的朋友可以参考,希望对大家学习JS有帮助,想要了解更多可以继续浏览群英网络其他相关的文章。
文本转载自脚本之家
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
js原生map实现的方法总结,一些朋友可能会遇到这方面的问题,对此在下文小编向大家来讲解一下,内容详细,易于理解,希望大家阅读完这篇能有收获哦,有需要的朋友就往下看吧!
这篇文章主要介绍了Vue 前端路由工作原理hash与history的区别,文章围绕主题展开vue-router的工作原理的简单介绍,感兴趣的朋友可以学习一下
这篇文章主要为大家详细介绍了jquery插件实现图片悬浮,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
目录文件如 httpFile.js如下:consthttpd=require("http");constfs=require("fs");//创建服务httpd.createServer((req,res)=>{//读取www文件夹下的路径fs.readFile(`www${req.url}`,(err,data)=>{
用jQuery怎样实现隐藏表的列元素?隐藏表的列元素还是比较实用的,本文实现的需求是隐藏表格里的某一列,这里使用到的方法是hide(),实现步骤及代码如下,需要的朋友可以参考,接下来跟随小编一起来学习一下吧。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008