用js写一个移动端网页
时间: 2023-09-28 16:09:57 浏览: 52
好的,以下是一个简单的移动端网页的HTML和JavaScript代码示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>移动端网页</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* 移动端网页的样式 */
body {
font-size: 16px;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
#container {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
#title {
font-size: 24px;
margin-bottom: 20px;
}
#button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="container">
<div id="title">欢迎使用移动端网页</div>
<button id="button">点击按钮</button>
</div>
<script>
// JavaScript代码
var button = document.getElementById("button");
button.addEventListener("click", function() {
alert("你点击了按钮");
});
</script>
</body>
</html>
```
这个网页包含一个居中的标题和一个按钮,当按钮被点击时会弹出一个提示框。CSS样式设置了页面的字体、居中、按钮样式等。JavaScript代码使用了DOM API获取按钮元素并添加了一个点击事件监听器,当按钮被点击时会弹出提示框。