js自定义信息提示框

代码:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	<button type="button" onclick="promptBox('信息提示和三个完全好人都不齐微积分军阀割据风格鞍山钢铁v奋斗成果哈斯v电话噶三个')">提示</button>
	<script>
		/**提示框
		 * @param {string} con:提示信息
		 * @param {boolean} sx:是否需要刷新页面
		 */
		function promptBox(con, sx = false) {
			var db = document;
			var w = window;
			if (w.parent != undefined) {
				db = w.parent.document;
			}
			var box = document.createElement("div");
			db.body.appendChild(box);
			box.style = "position: fixed;left:0;right:0;top:0;bottom:0;z-index:200;";
			var div = document.createElement("div");
			box.appendChild(div);
			div.style =
				"width:500px;height:200px;padding:10px;border-radius:5px;background-color: #fff;box-shadow: 2px 0 2px #666 , -2px 0 2px #666,0 2px 2px #666,0 -2px 2px #666;position: absolute;top:50%;margin-top:-100px;left:50%;margin-left:-250px;";
			var h2 = document.createElement("h2");
			h2.innerHTML = "提示信息";
			h2.style = "line-height:40px;height:40px;font-size:20px;text-align:center;border-bottom:1px solid #ccc;margin:0;";
			div.appendChild(h2);
			var condiv = document.createElement("div");
			condiv.innerHTML = con;
			condiv.style =
				"line-height:24px;font-size:16px;border-bottom:1px solid #ccc;text-indent: 2rem;padding:5px;height:95px;";
			div.appendChild(condiv);
			var btn = document.createElement("div");
			div.appendChild(btn);
			btn.style = "text-align:right;padding:5px;height:45px;";
			btn.innerHTML = `<button>确定</button>`;
			var qd = btn.children[0];
			qd.onclick = function () {		
				db.body.removeChild(box);
				if (sx) {
					w.location.reload();
		        }
			}
		}
	</script>
</body>
</html>

效果:

注:提示框位置默认在屏幕正中央

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值