<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车</title>
</head>
<body>
单价:<span id="dan">50</span>
数量:<button id="jian">-</button>
<span id="shu">1</span>
<button id="jia">+</button>
总价:<span id="zong">50</span>
<script>
var dan=document.getElementById('dan');
var jian=document.getElementById('jian');
var shu=document.getElementById('shu');
var jia=document.getElementById('jia');
var zong=document.getElementById('zong');
jian.οnclick=function(){
var num=shu.innerHTML;
num--;
shu.innerHTML=num;
var x=dan.innerHTML;
var sum=x*num;
zong.innerHTML=sum;
}
jia.οnclick=function(){
var num=shu.innerHTML;
num++;
shu.innerHTML=num;
var x=dan.innerHTML;
var sum=x*num;
zong.innerHTML=sum;
}
</script>
</body>
</html>