html电影购票网站,,不用JavaScript
时间: 2024-05-16 17:15:43 浏览: 13
可以使用 HTML 和 CSS 来创建一个基本的电影购票网站,但是如果需要实现一些交互功能,比如点击电影海报弹出购票页面等,就需要 JavaScript 的支持。
以下是一个简单的 HTML 和 CSS 代码示例,用于创建一个电影列表页面:
```html
<!DOCTYPE html>
<html>
<head>
<title>电影列表</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
h1 {
text-align: center;
margin-top: 50px;
color: #333;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-top: 30px;
}
.movie {
display: flex;
flex-direction: column;
align-items: center;
margin: 20px;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 5px #ccc;
}
.poster {
width: 200px;
height: 300px;
background-color: #eee;
margin-bottom: 10px;
}
.title {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
text-align: center;
}
.description {
font-size: 14px;
color: #666;
text-align: center;
}
</style>
</head>
<body>
<h1>电影列表</h1>
<div class="container">
<div class="movie">
<div class="poster"></div>
<div class="title">肖申克的救赎</div>
<div class="description">主演:蒂姆·罗宾斯 / 摩根·弗里曼 / 鲍勃·冈顿</div>
</div>
<div class="movie">
<div class="poster"></div>
<div class="title">阿甘正传</div>
<div class="description">主演:汤姆·汉克斯 / 罗宾·怀特 / 加里·西尼斯</div>
</div>
<div class="movie">
<div class="poster"></div>
<div class="title">霸王别姬</div>
<div class="description">主演:张国荣 / 张丰毅 / 巩俐</div>
</div>
</div>
</body>
</html>
```
这段代码创建了一个电影列表页面,包含三个电影海报、电影名称和主演等信息。
但是,如果需要在点击海报时弹出购票页面,就需要使用 JavaScript 实现相关功能,例如:
```javascript
// 获取所有电影海报元素
var posters = document.querySelectorAll('.poster');
// 遍历每个电影海报元素
for (var i = 0; i < posters.length; i++) {
// 给每个电影海报元素添加点击事件
posters[i].addEventListener('click', function() {
// 弹出购票页面
alert('购票页面');
});
}
```
这段代码使用了 JavaScript 的 DOM 操作,给每个电影海报元素添加了点击事件,并在点击时弹出了购票页面。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)