建站代码网

热门标签

ecshop的商品详细页面添加“加”,“减”按钮的方法

1.添加两个js. 
   

<script language="javascript" type="text/javascript"> function goods_cut(){ var num_val=document.getElementByIdx_x('number'); var new_num=num_val.value; var Num = parseInt(new_num); if(Num>1)Num=Num-1; num_val.value=Num; } function goods_add(){ var num_val=document.getElementByIdx_x('number'); var new_num=num_val.value; var Num = parseInt(new_num); Num=Num+1; num_val.value=Num; } </script>  

2.在购买数量的文本框两遍分别添加“加”,“减”按钮!
   

<li class="gmsl">购买数量:<a href="javascript:;" onclick="goods_add();changePrice();"class="adds"></a><span> <input name="number" type="text" id="number" value="1" size="4" onblur="changePrice()" style="border:1px solid #ccc; "/></span><a href="javascript:;"onclick="goods_cut();changePrice();" class="jian"></a><li>