的方法如下:
<!DOCTYPE html>
<html>
<head>
<title>随机数列表</title>
<style>
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<button onclick="openModal()">显示随机数列表</button>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<h2>随机数列表</h2>
<ul id="randomList"></ul>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
function openModal() {
var modal = document.getElementById("myModal");
modal.style.display = "block";
generateRandomList();
}
function closeModal() {
var modal = document.getElementById("myModal");
modal.style.display = "none";
}
function generateRandomList() {
var randomList = document.getElementById("randomList");
randomList.innerHTML = "";
for (var i = 0; i < 10; i++) {
var randomNumber = Math.floor(Math.random() * 100);
var listItem = document.createElement("li");
listItem.textContent = randomNumber;
randomList.appendChild(listItem);
}
}
这个例子中,我们使用了JavaScript来生成随机数列表,并将其显示在Modal上。当点击按钮时,Modal弹出并显示随机数列表,点击Modal上的关闭按钮或背景区域,Modal关闭。
领取专属 10元无门槛券
手把手带您无忧上云