var num = document.getElementById("num" + id)
var getNum = parseInt(num.value)
if(getNum > 1){
num.value = getNum - 1
}
}
function addNum(id){
var num = document.getElementById("num" + id)
num.value = parseInt(num.value) + 1
}
或者
var num = document.getElementById("num" + id)function subNum(id) {
var getNum = parseInt(num.value)
if(getNum > 1){
num.value = getNum - 1
}
}
function addNum(id){
num.value = parseInt(num.value) + 1
}
方法只有一种:
直接使用减号运算符进行减法运算
举例:var a=2
var b=1
var c=a-b//这里通过减号运算符进行减法运算