1.要能实现加和减两个功能 
2.且有两个按钮和一个计数框 
3.按一下按钮计数框加一或减一 
4.计数器范围在0-10 
5.超出范围弹出警告框“你输入的数超出范围” 
6.要用javascript实现 请高手指点一下

解决方案 »

  1.   

    <html>
    <script type="text/javascript">
      function toCount(obj){
        var countComp = document.getElementById('count');
        var countVal = countComp.value;
        if(obj.id == "jian"){
            --countVal;
           if(countVal <0){
                alert("计数器范围在0-10");
                return;
           }else{
             countComp.value = countVal;
           }
        }else{
           ++countVal;
           if(countVal >10){
                alert("计数器范围在0-10");
                return;
           }else{
             countComp.value = countVal;
           }
        }
      }
      
    </script>
    <table>
     <tr>
      <td>
    <input type="text" id="count" value="0">
      </td>
     <td>
    <input type="button" id="jian" onclick="toCount(this)">
      </td>
     <td>
    <input type="button" id="add" onclick="toCount(this)">
      </td>
    </tr>
    </table>
      
      
    </html>
      

  2.   


    <html>
    <head>
        <title></title>
        <script type="text/javascript">
            function add() {
                if (document.getElementById("values").value < 10) {
                    document.getElementById("values").value++
                } else {
                    alert("你输入的数超出范围")
                }
            }
            function dec() {
                if (document.getElementById("values").value > 0) {
                    document.getElementById("values").value--
                } else {
                    alert("你输入的数超出范围")
                }
            }
        </script>
    </head>
    <body>
        <input type="text" id="values" value="0" />
        <input type="button" value="加" onclick="add()" />
        <input type="button" value="减" onclick="dec();" />
    </body>
    </html>