用JS怎样做一个简易的消息提示框?
Admin 2021-10-25 群英技术资讯 1716 次浏览
今天给大家分享的是用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实现时间选择器,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要介绍了Webpack的Loader和Plugin的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
这篇文章主要为大家详细介绍了JavaScript实现简易折叠面板,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
目录累加/累积求最大/最小值格式化搜索参数反序列化搜索参数拉平嵌套数组实现 flat数组去重数组计数获取对象多个属性反转字符串不知道大家平常用 Reduce 多不多,反正本瓜用
数组是一种特殊对象。js中并没有真正的数组,只是用对象模拟数组。数组是值的有序集合,每一个值叫做一个元素,而每一个元素在数组中有一个位置,以数字表示,称为所以。而JS中没有真正的数组,只是用对象模拟数组。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008