标签:red 点击 body 最小数 element dem get type title
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>安心牧羊人</title>
</head>
<body>
<p>全局变量计数。</p>
<button type="button" onclick="myFunction1()">-</button>
<span id="demo" style="color:red;">0</span>
<button type="button" onclick="myFunction2()">+</button>
<script>
var counter=0;
function add() {
if(counter>=10){ //设置库存最大数例如10以上不能点击加
return counter += 0;
}else{
return counter += 1;
}
return counter += 1;
}
function cor() {
if(counter===0){ //设置最小数值不能低于0 ,低于0不能点击
return counter += 0;
}else{
return counter += -1;
}
}
function myFunction1(){
document.getElementById("demo").innerHTML = cor();
}
function myFunction2(){
document.getElementById("demo").innerHTML = add();
}
</script>
</body>
</html>
标签:red 点击 body 最小数 element dem get type title
原文地址:http://www.cnblogs.com/gerry/p/7562777.html