在购物网站上  当看具体某个商品时在旁边会显示出 要买商品的数量  这个数量是可以改变的在数量的文本框中  紧挨的右边 有个上下点击器
不知道是怎么用js写的 谢谢大家

解决方案 »

  1.   


    <script> 
    function doup(id){
    var obj = document.getElementById(id);
    if(isNaN(obj.value)) return false;
    obj.value = parseInt(obj.value,10)+1;
    }
    function dodown(id){
    var obj = document.getElementById(id);
    if(isNaN(obj.value)) return false;
    if(parseInt(obj.value,10)==0) obj.value = 0;
    else obj.value = parseInt(obj.value,10)-1;
    }</script> <table>
     <tr>
       <td width="200"><input id="p_0" name="p_0" style="width:100%;" value="1"></td>
       <td width="20">
         <input type="button" style="width:20px;height:10px;float:left;" onclick="doup('p_0')"><input type="button" style="float:left;width:20;height:10px;display:inline-block;" onclick="dodown('p_0')">
       </td>
    </tr>
    </table>
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      
      <style>
      body {
    font-size: 12px;
    margin: 0px;
    padding: 0px;
      }
      .title {
    height: 15px;
    width: 138px;
    display:block;
    text-decoration: none;
    cursor: pointer;
    text-align: center;
    line-height: 15px;
    border: 1px dashed #FFFF99;
    background-color: #D9D9D9
      }
      #content {
    display:none;
      }
      </style>
      <script type="text/javascript">
      <!--
    var total = 0;
    function showCont(){
    document.getElementById("content").style.display = "block";
    }
    window.onload = function(){
    total = parseInt(document.getElementById("num").value, 10);
    }
    function addNum(){
    document.getElementById("num").value = ++total;
    }
    function minNum(){
    total > 0 && (document.getElementById("num").value = --total);
    }
      //-->
      </script>
     </head> <body>
      <a href="javascript:void(0);" onclick= "showCont()" class="title">查看商品</a>
      <div id="content">
      <img src="http://t2.baidu.com/it/u=716949918,3595690352&fm=2&gp=13.jpg"/><br/>
      <input type="text" id="num" value="12" style="width:22px;"/>
      <input type="button" value="+" onclick="addNum();" />
      <input type="button" value="-" onclick="minNum();" />
      </div>
     </body>
    </html>