老师 麻烦批改一下

来源:2-12 自由编程

weixin_慕斯卡1279472

2021-03-25 16:57:54

<!DOCTYPE html>
<html lang="zh-CN">

<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>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

body {
width: 100%;
height: 1200px;
}

.message-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(204, 204, 204, .5);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.message-box {
width: 200px;
background-color: #fff;
border-radius: 10px;
padding: 10px;
text-align: center;
box-shadow: 0 0 3px 0 rgba(0, 0, 0, .25);
}

.message-content {
padding: 30px 0;
}

.message-options {
height: 30px;
display: flex;
justify-content: space-around;
align-content: center;
}

.message-btn {
width: 80px;
height: 100%;
color: white;
background-color: rgba(0, 122, 204);
border: none;
outline: none;
-webkit-tap-highlight-color: transparent;
cursor: pointer;
}

.cancel {
background-color: #ccc;
}
</style>
</head>

<body>
<h1>我是被遮罩的内容层</h1>
<h2>点我弹出指定内容框</h2>
<input type="text" id="testContent" value="是否确认删除?">
<button onclick="test()">信息框</button>
<div class="message-container" id="message-container" v-show='isShow'>
<div class="message-box">
<div class="message-content">
{{ content }}
</div>
<div class="message-options">
<button class="message-btn cancel" @click="cancel">取消</button>
<button class="message-btn confirm" @click="confirm">确认</button>
</div>
</div>
</div>
<script src="node_modules/vue/dist/vue.js"></script>
<script>
let messageBox = new Vue({
el: "#message-container",
data: {
content: "请确认是否要删除?",
isShow: false,
callback: function () { }
},
methods: {
msg(content, callback) {
this.isShow = true;
this.content = content;
this.callback = callback;
},
cancel() {
this.isShow = false;
this.callback(false);
},
confirm() {
this.isShow = false;
this.callback(true);
}
}
});
function test() {
messageBox.msg(document.getElementById("testContent").value, function (result) {
if (result) {
alert("成功点击了确认按钮");
} else {
alert("取消了点击");
}
});
}
</script>
</body>

</html>


写回答

1回答

好帮手慕言

2021-03-25

同学你好,如下:

1、按照要求,内容盒子宽度设置50% ,参考:
http://img.mukewang.com/climg/605c62400918e78c04010158.jpg

2、取消和确认按钮添加上圆角,效果会更美观,参考:
http://img.mukewang.com/climg/605c626c0959475503960140.jpg

另外:此编程题实现一个静态页面即可,不用添加js代码,祝学习愉快~

0

0 学习 · 15276 问题

查看课程