html+js 点击按钮实现 加1 和 减1 操作

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>购物数量小程序</title>
</head>

<body>
<script>
    var sum=0;
    function jian()
    {
        sum--;
        if(sum<0) sum=0;
        document.getElementById("t1").value=sum;
    }
    function jia()
    {
        sum++;
        document.getElementById("t1").value=sum;
    }
</script>
<table>
<tr>
<td>购买数量
<td><button name="-" id="jian" onClick="jian()">-</button>
<td><input type="text" id="t1" value="0">
<td><button name="+" id="jia" onClick="jia()">+</button>
</tr>
</body>
</html>
0

Leave a Reply

Your email address will not be published.