<button class="jian-btn" onclick="reduce()" type="button">-</button>
<input id="buy-num" type="text" value="1" name="Num">
<button class="jia-btn" onclick="add()" type="button">+</button>
<script type="text/javascript">
function add(){
var num=document.getElementById("buy-num");//获取数量ID
var a=num.value;//获取数量
if(a < <?=$rsa["kc"]?>){//<?=$rsa["kc"]?>这个是库存,数字自行修改,如果小于库存
a++;//++
num.value=a;//变化后的值赋值给,数量ID的值
}else{//值超出库存
alert('不能在多啦!');//提示
a=<?=$rsa["kc"]?>;//把当前库存值赋值给,数量ID的值
num.value=a;//把当前库存值赋值给,数量ID的值
}
console.log(a);
}
function reduce(){
var num=document.getElementById("buy-num");
var b=num.value;
if(b<2){
alert('不能在小啦!');
b=1;
num.value=b;
}else{
b--;
num.value=b;
}
console.log(b);
}
</script>
最后
以上就是热心诺言最近收集整理的关于JS控制数量多少问题++/--的全部内容,更多相关JS控制数量多少问题++/--内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复