当前位置:网站首页>JS模态框
JS模态框
2022-07-17 03:49:00 【郭郭郭憨憨】
代码展示:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="./css/model.css">
</head>
<body>
<!-- css样式引用的,js是自己写的 -->
<div id="model" style="display: none;">
<div class="modelDialog">
<span class="close" style="display: none;">x</span>
<div class="title">
退出游戏
</div>
<div class="content">
<div class="subject">确认退出游戏?</div>
<div class="options">
<div class="btn confirm">确认</div>
<div class="btn cancel">取消</div>
</div>
</div>
</div>
</div>
<button>68元购买胡桃!!</button><button>168元购买胡桃的皮肤!!</button><button>退出游戏</button>
<script>
var model=document.querySelector("#model");
var btns=document.querySelectorAll("button");
var buts=document.querySelectorAll(".btn");
function changeText(title,subject,confirm,cancel,close){
var titleEle=document.querySelector(".title");
titleEle.innerText=title;//更换标题
var subjectEle=document.querySelector(".subject");
subjectEle.innerText=subject;//更换内容
var confirmEle=document.querySelector(".confirm");
confirmEle.innerText=confirm;
var cancelEle=document.querySelector(".cancel");
cancelEle.innerText=cancel;
closeEle=document.querySelector(".close");
if(close){
closeEle.style.display="inline-block";//根据需求选择是否想要X
}else{
closeEle.style.display="none";//根据需求选择是否想要X
}
}
btns[0].onclick=function(){
model.style.display="flex";
changeText("购买英雄","确认购买胡桃吗?","确认购买","我再想想吧",true);
closeEle.onclick=function(){
model.style.display="none";
}
buts[0].onclick=function(){
changeText("购买成功","恭喜你,已经拥有胡桃","查看角色","返回",false);
buts[0].onclick=function(){
model.style.display="none";
}
buts[1].onclick=function(){
model.style.display="none";
}
}
buts[1].onclick=function(){
model.style.display="none";
}
}
btns[1].onclick=function(){
model.style.display="flex";
changeText("购买皮肤?","确认购买胡桃的皮肤吗?","确认购买","我再想想吧",true);
closeEle.onclick=function(){
model.style.display="none";
}
buts[0].onclick=function(){
changeText("购买成功","恭喜你,已经拥有胡桃的皮肤","查看皮肤","返回",false);
buts[0].onclick=function(){
model.style.display="none";
}
buts[1].onclick=function(){
model.style.display="none";
}
}
buts[1].onclick=function(){
model.style.display="none";
}
}
btns[2].onclick=function(){
model.style.display="flex";
changeText("退出游戏","确认退出游戏吗?","确认退出","返回",false);
buts[0].onclick=function(){
model.style.display="none";
}
buts[1].onclick=function(){
model.style.display="none";
}
}
</script>
</body>
</html>
结果展示:(样式比较简单)
边栏推荐
- SQL interface switching cannot obtain focus
- MAUI 框架入門學習05 MVVM數據模型理解
- Mqant in-depth analysis
- What does the project set price mean?
- 小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(3)后台功能
- Unity shader - "fast SSS: fast subsurface scattering"
- Wechat online education video on demand learning applet graduation design (3) background function
- 小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(2)小程序功能
- Software testing - use cases
- Codeforces Round #807 (Div. 2) A~D
猜你喜欢
Introduction to PLC OPC information model (DI, PLCopen nodesets)
Xcode11 add a boot page (the launch images source option is missing after the upgrade)
mqant 深入分析
Wechat e-book reading of small program graduation design (5) task book
In tech 2022 | Intel technology product innovation quick view
[Huang ah code] Introduction to MySQL - 5. Database tips: a single column group by will, and multiple columns?
小程序毕设作品之微信电子书阅读小程序毕业设计(1)开发概要
Wechat e-book reading applet graduation design of applet completion works (1) development outline
64. 最小路径和:给定一个包含非负整数的 m x n 网格 grid ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。 说明:每次只能向下或者向右移动一步。
如何更有效的过滤病毒/垃圾邮件!
随机推荐
SQL interface switching cannot obtain focus
Insert the laptop into the headset and still play it out (the personal test is valid)
小程序毕设作品之微信电子书阅读小程序毕业设计(5)任务书
Use of anti shake debounce and throttling throttle
Openresty as a static resource server
MAUI 框架入門學習05 MVVM數據模型理解
Build a portrait matting server based on openvino model server
小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(1)开发概要
Ftxui basic notes (botton button component Foundation)
How to filter viruses / spam more effectively!
minimum spanning tree
Wkwebview white screen
基于OpenVINO Model Server打造人像抠图服务器
leetcode209. 长度最小的子数组
笔记本电脑插入耳机仍然外放(亲测有效)
High performance and economy: aoteng persistent memory helps mobile cloud cope with severe memory challenges
Live broadcast of cloud intelligence face to face is waiting for you: computing power redefines productivity
【微信小程序】超易懂的条件渲染和列表渲染
【数据库】期末必知必会-----第二章 关系数据模型
Machine learning 10: Integrated Learning