zoukankan      html  css  js  c++  java
  • 商品

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Document</title>
    </head>
    <body>
    	
    	<div id="num1">
    		<span>商品一</span>
    		<button class="btnReduce" sign="false">-</button>
    		<span class="each">0</span>
    		<button class="btnadd" sign="true">+</button>&nbsp;&nbsp;&nbsp;&nbsp;
    		<span>价格</span>
    		<span class="sum">0</span>
    	</div>
    
    	<div id="num2">
    		<span>商品二</span>
    		<button class="btnReduce" sign="false">-</button>
    		<span class="each">0</span>
    		<button class="btnadd" sign="true">+</button>&nbsp;&nbsp;&nbsp;&nbsp;
    		<span>价格</span>
    		<span class="sum">0</span>
    	</div>
    
    	<div id="num3">
    		<span>商品三</span>
    		<button class="btnReduce" sign="false">-</button>
    		<span class="each">0</span>
    		<button class="btnadd" sign="true">+</button>&nbsp;&nbsp;&nbsp;&nbsp;
    		<span>价格</span>
    		<span class="sum">0</span>
    	</div>
    
    	<div>
    		<span>一共</span>
    		<span class="pieces">0</span>
    		<span>件</span>
    		<span>合计</span>
    		<span class="countSum">0</span>
    	</div>
    
    
    	<script type="text/javascript">		
    	var btnReduce = document.getElementsByClassName("btnReduce"),
    	 	btnadd = document.getElementsByClassName("btnadd"),
    		each = document.getElementsByClassName("each"),
    	 	sum = document.getElementsByClassName("sum"),
    	 	pieces = document.getElementsByClassName("pieces")[0],
    	 	countSum = document.getElementsByClassName("countSum")[0],
    	 	eachEvery = [0,0,0],eachEverySum = [0,0,0],num = 5,count=0,piecesCount=0;
    
    	for(var i=0;i<btnReduce["length"];i++){
    		btnReduce[i]["onclick"] = btnadd[i]["onclick"] = function(i){
    			return function(e){
    				this.getAttribute("sign")=="true" ? eachEvery[i]++ : eachEvery[i]--;
    			    eachEvery[i] < 0 ? eachEvery[i] = 0 : eachEvery[i];
    				eachEverySum[i] = eachEvery[i] * num;
    				count = eval(eachEverySum.join("+"));
    				piecesCount = eval(eachEvery.join("+"));
    				each[i].innerHTML = eachEvery[i];
    				sum[i].innerHTML = eachEverySum[i];
    				countSum.innerHTML = count;
    				pieces.innerHTML = piecesCount;
    			}
    		}(i)
    	}		
    
    	</script>	
    </body>
    </html>
    
  • 相关阅读:
    无法加载模块 TP3.2
    always_populate_raw_post_data
    关于(void**)及其相关的理解
    面向对象设计原则
    数据对齐总结
    C++ POD类型
    do..while(false)的用法总结
    c++为什么定义了析构函数的类的operator new[]传入的参数会多4字节?
    C++ new new[]详解
    【转】C内存操作函数
  • 原文地址:https://www.cnblogs.com/liu-di/p/10608239.html
Copyright © 2011-2022 走看看