<!DOCTYPE html>
<html>
<head>
<title>购物车加减</title>
<meta charset="utf-8">
<style type="text/css">
<html>
<head>
<title>购物车加减</title>
<meta charset="utf-8">
<style type="text/css">
div{
height: 30px;
}
input{
width: 50px;
height:32px;
background: white;
border:1px solid #CCC;
float: left;
}
height: 30px;
}
input{
width: 50px;
height:32px;
background: white;
border:1px solid #CCC;
float: left;
}
span{
width: 100px;
height: 30px;
text-align: center;
display:inline-block;
border:1px solid #CCC;
line-height: 30px;
float: left;
}
</style>
</head>
<body>
<div>
<input type="button" value="-" οnclick="less()">
<span>1</span>
<input type="button" value="+" οnclick="add()">
</div>
</body>
<script type="text/javascript">
var span=document.getElementsByTagName('span');
var num=parseInt(span[0].innerHTML);
function less(){
if (num==1) return;
num--;
span[0].innerHTML=num;
}
function add(){
if(num>=100)return;
num++;
span[0].innerHTML=num;
}
</script>
</html>