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{ 40px; height:16px; line-height:16px; border:1px solid #CCC; text-align:center; float:left; margin:0 5px;} #add,#jian{ 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="-" />