加减数量购物车切片

jq包+JS

<script src="jquery-1.7.1.min.js"></script>
<script>
$(document).ready(function(){
$("#add").click(function(){
  var n=$("#num").val();
  var num=parseInt(n)+1;
 if(num==0){alert("cc");}
  $("#num").val(num);
});
$("#jian").click(function(){
  var n=$("#num").val();
  var num=parseInt(n)-1;
 if(num==0){alert("不能为0!"); return}
  $("#num").val(num);
  });
});
</script>

css

 

<style><br>
body { font-family: Arial; font-size:16px;}
#num{ width:40px; height:16px; line-height:16px; border:1px solid #CCC; text-align:center;  float:left; margin:0 5px;}
#add,#jian{ width:26px; height:20px; float:left; border:1px solid #ccc; background:#eee; cursor:pointer;}
</style>

 

html

<input type="button" id="add" value="+" />
<input type="text" id="num" value="3" />
<input type="button" id="jian" value="-" />
posted @ 2013-05-11 08:39  哈达波斯网络  阅读(170)  评论(0编辑  收藏  举报