产品列表和购物车(布局)有两个单独的页面。现在,当我单击“添加到购物车”按钮时,我需要向购物车中添加项目,并且当我单击购物车(链接)时,它应该重定向到购物车页面。我希望这仅在javascript和html中。我知道购物车最初会是空的,我想将物品添加到空购物车中。
这是我的项目的代码。我为此使用了Bootstrap。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mystore</title>
<link href="css/bootstrap.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="cart.html" style="color: coral; font-size:18px" onMouseOver="this.style.color='white'" ; onMouseOut="this.style.color='coral'">cart</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="ecommerce.html" style="font-size:20px" onMouseOver="this.style.color='coral'" ; onMouseOut="this.style.color='white'">Home<span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</div>
</nav>
<br>
<h1 class="text-center">Hurry up! Sale ends soon.</h1>
<hr>
<div class="container">
<div class="row text-center">
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_tshirt.html"><img class="card-img-top" src="images/052.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_tshirt.html">
<h5 class="card-title">Men's T-shirt</h5>
</a>
<p class="card-text">Awesome Black and White T-shirt for men.
<b>Best Buy @299/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_shoe.html"><img class="card-img-top" src="images/74ea1cfb-056e-4dd7-8e19-e732dfba56eb.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_shoe.html">
<h5 class="card-title">Premium Shoe</h5>
</a>
<p class="card-text">Best quality yellow color shoe.
<b>Best But @499/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_smartphone.html"><img class="card-img-top" src="images/81UhvwBU-EL._SX466_.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_smartphone.html">
<h5 class="card-title">Smartphone</h5>
</a>
<p class="card-text">Buy the brand new smartphone.
<b>Best Buy @9999/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
</div>
<div class="row text-center mt-4">
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_laptop.html"><img class="card-img-top" src="images/alienwarem17.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_laptop.html">
<h5 class="card-title">Gaming Laptop</h5>
</a>
<p class="card-text">High spec Gaming laptop for Gamers.
<b>Best Buy @49999/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_trouser.html"><img class="card-img-top" src="images/s5q-mens-harem-trousers-skinny-pants-legging.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_trouser.html">
<h5 class="card-title">Men's Trousers</h5>
</a>
<p class="card-text">Stylish Grey trouser for men.
<b>Best Buy @399/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_watch.html"><img class="card-img-top" src="images/gentlemen-s-club-leather-band-wristwatch-6_large.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_watch.html">
<h5 class="card-title">Wrist Watch</h5>
</a>
<p class="card-text">Branded mens Wrist Watch.
<b>Best Buy @999/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
</div>
<div class="row text-center mt-4">
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_headphones.html"><img class="card-img-top" src="images/h069playh2silver-00.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_headphones.html">
<h5 class="card-title">Headphones</h5>
</a>
<p class="card-text">Best-in-class Premium Headphones.
<b>Best Buy @799/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_speaker.html"><img class="card-img-top" src="images/u_10159856.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_speaker.html">
<h5 class="card-title">Bluetooth Speaker</h5>
</a>
<p class="card-text">Waterproof Bluetooth speaker. <i>Limited edition</i>
<b>Best Buy @699/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
<div class="col-md-4 pb-1 pb-md-0">
<div class="card">
<a href="product details/product_camera.html"><img class="card-img-top" src="images/canon_eos_rebel_t3i_with_18-135mm_f3.5-5.6_is_lens.jpg" alt="Card image cap"></a>
<hr>
<div class="card-body">
<a href="product details/product_camera.html">
<h5 class="card-title">Dslr Camera</h5>
</a>
<p class="card-text">Additional lens with this product.
<b>Best Buy @15999/-</b></p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
</div>
</div>
<hr>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
以下是购物车布局的代码。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="cart.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="cart.html" style="color: coral; font-size:18px" onMouseOver="this.style.color='white'" ; onMouseOut="this.style.color='coral'">cart</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="ecommerce.html" style="font-size:20px" onMouseOver="this.style.color='coral'" ; onMouseOut="this.style.color='white'">Home<span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</div>
</nav>
<br><br>
<div class="container">
<div class="card">
<table class="table table-hover shopping-cart-wrap">
<thead class="text-muted">
<tr>
<th scope="col">Product</th>
<th scope="col" width="120">Quantity</th>
<th scope="col" width="120">Price</th>
<th scope="col" width="200" class="text-right">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<figure class="media">
<div class="img-wrap"><img src="images/052.jpg" class="img-thumbnail img-sm"></div>
<figcaption class="media-body">
<h6 class="title text-truncate">Men's T-shirt </h6>
<dl class="param param-inline small">
<dt>Size: </dt>
<dd>L</dd>
</dl>
<dl class="param param-inline small">
<dt>Color: </dt>
<dd>Black & White</dd>
</dl>
</figcaption>
</figure>
</td>
<td>
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</td>
<td>
<div class="price-wrap">
<var class="price">299 /-</var>
<small class="text-muted">(299 each)</small>
</div>
<!-- price-wrap .// -->
</td>
<td class="text-right">
<a href="" class="btn btn-outline-danger"> × Remove</a>
</td>
</tr>
<tr>
<td>
<figure class="media">
<div class="img-wrap"><img src="images/74ea1cfb-056e-4dd7-8e19-e732dfba56eb.jpg" class="img-thumbnail img-sm"></div>
<figcaption class="media-body">
<h6 class="title text-truncate">Premium Shoe </h6>
<dl class="param param-inline small">
<dt>Size: </dt>
<dd>10</dd>
</dl>
<dl class="param param-inline small">
<dt>Color: </dt>
<dd>Yellow color</dd>
</dl>
</figcaption>
</figure>
</td>
<td>
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</td>
<td>
<div class="price-wrap">
<var class="price">500 /-</var>
<small class="text-muted">(500 each)</small>
</div>
<!-- price-wrap .// -->
</td>
<td class="text-right">
<a href="" class="btn btn-outline-danger btn-round"> × Remove</a>
</td>
</tr>
<tr>
<td>
<figure class="media">
<div class="img-wrap"><img src="images/81UhvwBU-EL._SX466_.jpg" class="img-thumbnail img-sm"></div>
<figcaption class="media-body">
<h6 class="title text-truncate">Smartphone </h6>
<dl class="param param-inline small">
<dt>Size: </dt>
<dd>64 gb</dd>
</dl>
<dl class="param param-inline small">
<dt>Color: </dt>
<dd>Black</dd>
</dl>
</figcaption>
</figure>
</td>
<td>
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</td>
<td>
<div class="price-wrap">
<var class="price">9999 /-</var>
<small class="text-muted">(9999 each)</small>
</div>
<!-- price-wrap .// -->
</td>
<td class="text-right">
<a href="" class="btn btn-outline-danger btn-round"> × Remove</a>
</td>
</tr>
</tbody>
</table>
</div>
<!-- card.// -->
</div>
<!--container end.//-->
<br><br>
</body>
</html>