<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>操作当当购物车页面</title>
<link type="text/css" rel="stylesheet" href="css/cartStyle.css" />
<script type="text/javascript" src="js/shopping.js"></script>
<script src="js/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript">
function del(){ //这里我写了个函数,但是 只能删除指定的信息,并不能就是我随机点击哪个删除,就删除某个信息
var cartList=document.getElementById("cartList");
cartList.parentNode.removeChild(cartList);
};
</script>
</head>
<body>
<div>
<div>
<img src="images/dd_logo.jpg"><span onclick="close_plan();">关闭</span>
</div>
<div >
<ul>
<li>商品图片</li>
<li>商品信息</li>
<li>单价</li>
<li>数量</li>
<li>总价</li>
<li>操作</li>
</ul>
<ul id="cartList">
<li><img src="images/dog.jpg"></li>
<li>我和狗狗活下来了</li>
<li>¥<input type="text" name="price" value="21.90"></li>
<li><input type="button" name="minus" value="-" onclick="minus(0);"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus(0);"></li>
<li id="price0">¥21.90</li>
<li><p onclick="collection();">移入收藏</p><p onclick="del();">删除</p></li>
</ul>
<ul>
<li><img src="images/mai.jpg"></li>
<li>灰霾来了怎么办</li>
<li>¥<input type="text" name="price" value="24.00"></li>
<li><input type="button" name="minus" value="-" onclick="minus(1);"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus(1);"></li>
<li id="price1">¥24.00</li>
<li><p onclick="collection();">移入收藏</p><p onclick="del();">删除</p></li>
</ul>
<ol>
<li id="totalPrice">商品总计:<span></span></li>
<li><span>结 算</span></li>
</ol>
</div>
</div>
<script type="text/javascript" src="js/shopping.js"></script>
</body>
</html>
//然后为了你们方便排错,我把js代码也发过来了
/**
* Created by zongjuan.wang on 2016/6/1.
*/
/*关闭窗口*/
function close_plan(){
window.close();
}
function collection(){
var flag=confirm("移入收藏后,将不再购物车显示,是否继续操作?");
if(flag==true){
alert("移入收藏成功!");
}
}
function minus(num){
var prices=document.getElementsByName("price")[num].value;
var count=parseInt(document.getElementsByName("amount")[num].value)-1;
if(count<1){
alert("不能再减了,再减就没有啦!");
}
else{
document.getElementsByName("amount")[num].value=count;
var totals=parseFloat(prices*count);
document.getElementById("price"+num).innerHTML="¥" +totals;
total();
}
}
function plus(num){
var prices=document.getElementsByName("price")[num].value;
var count=parseInt(document.getElementsByName("amount")[num].value)+1;
document.getElementsByName("amount")[num].value=count;
var totals=parseFloat(prices*count);
document.getElementById("price"+num).innerHTML="¥" +totals;
total();
}
function total(){
var prices=document.getElementsByName("price");
var count=document.getElementsByName("amount");
var sum=0;
for(var i=0; i<prices.length;i++){
sum+=prices[i].value*count[i].value;
}
document.getElementById("totalPrice").getElementsByTagName("span")[0].innerHTML="¥" +sum;
}
total();
李晓健
相关分类