本帖最后由 blue903 于 2012-02-23 15:43:52 编辑

解决方案 »

  1.   

    你发的那个链接稍微改下不就行了,不会改吗。。<!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <span id="add">+</span>
    <input type="text" value="0" id="text"/>
    <span id="reduce">-</span>
    <script>
    function $(id){
    return document.getElementById(id);
    }
    var elems = {
    add: $('add'),
    reduce: $('reduce'),
    text: $('text')
    }
    elems.add.onclick = function(){
    elems.text.value++;
    }
    elems.reduce.onclick = function(){
    elems.text.value--;
    }
    </script>
    </body>
    </html>
      

  2.   

    <html>
    <head>
        <title></title>
        <style type="text/css">
            span
            {
                border: 1px solid gray;
                cursor: pointer;
                color: Gray;
                height: 2px;
                width: 2px;
            }
        </style>
        <script type="text/javascript">
            function autoPlusMinus() {
                var operator = event.srcElement.innerText;
                if (operator != "+" && operator != "-") {
                    return;
                }
                var oldValue = number.value;
                if (isNaN(oldValue)) {
                    number.value = "0";
                }
                oldValue = parseFloat(number.value);
                number.value = eval(oldValue + operator + 1).toString();
            }
            document.onclick = autoPlusMinus;
        </script>
    </head>
    <body>
        <span id="plus">+</span>&nbsp;<input id="number" type="text" value="0" style="width: 40px;
            text-align: center;" />&nbsp;<span id="minus">-</span>
    </body>
    </html>