解决方案 »

  1.   

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
    <input type="button" value="b1" /><input type="text" />
    <input type="button" value="b2" /><input type="text" />
    <input type="button" value="b3" /><input type="text" />
    <input type="button" value="b4" /><input type="text" />
    <script>
        var inputs=document.getElementsByTagName('input'),
                bs=[],ts=[];
        for(var i= 0,len=inputs.length;i<len;i++){
            var type=inputs[i].type;
            if(type=='button'){
                bs.push(inputs[i]);
            }
            if(type=='text'){
                ts.push(inputs[i]);
            }
        }
        function findIndex(dom){
            for(var i= 0,len=bs.length;i<len;i++){
                if(bs[i]==dom){
                    return i;
                }
            }
            return -1;
        }
        document.body.onclick=function(e){
            var a=e||window.event,
                 target= a.srcElement|| a.target;
            if(target.type=='button'){
                ts[findIndex(target)].value=target.value;
            }
        }
    </script>
    </body>
    </html>
      

  2.   

    <script type="text/javascript">
    function down(id)
    {
    document.getElementById(id).value++;
    }
    function up(id)
    {
    document.getElementById(id).value--;
    }
    </script>
    <input type="text" id="id0" value="1"/><input type="button" value="+" onclick="down('id0')"/><input type="button" value="-" onclick="up('id0')"/><br />
    <input type="text" id="id1" value="1"/><input type="button" value="+" onclick="down('id1')"/><input type="button" value="-" onclick="up('id1')"/><br />
    <input type="text" id="id2" value="1"/><input type="button" value="+" onclick="down('id2')"/><input type="button" value="-" onclick="up('id2')"/><br />
    <input type="text" id="id3" value="1"/><input type="button" value="+" onclick="down('id3')"/><input type="button" value="-" onclick="up('id3')"/><br />
      

  3.   


    <input type="button" class='btn'  value="btn1" /><input type="text" />
    <input type="button" class='btn' value="btn2" /><input type="text" />
    <input type="button" class='btn' value="btn3" /><input type="text" />
    <input type="button" class='btn' value="btn4" /><input type="text" /><script>
    $(".btn").click(function(){
    var a='www.ljiong.com';
    $(this).next('input').val(a);
    })
    </script>
      

  4.   

    谢两位了,不过
    按钮和文本框也是用 JS 添加的, 但是两个的位置没在一起, 也没ID  
      

  5.   

    js 的这样写<script>
    window.onload = function() {
      document.body.onclick = function(e) {
        e = e || event;
        var el = e.target || e.srcElement;
        if(el.type != 'button') return;
        var  x = document.getElementsByTagName('input');
        var b = 0, t = 0;
        for(var i=0; i<x.length; i++) {
          if(x[i].type == 'button') {
            if(x[i] == el) break;
            b++;
          }
        }
        for(var i=0; i<x.length; i++) {
          if(x[i].type == 'text') {
            if(t == b) {
              x[i].focus();
              break;
            }
            t++;
          }
        }
      }
    }
    </script>
    <body>
    <div>
    <input type="button" value="btn1" />
    <input type="button" value="btn2" />
    <input type="button" value="btn3" />
    <input type="button" value="btn4" />
    </div>
    <div>
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    </div>
    </body>
    无论按钮和文本框是如何产生的,都将按生成次序一一对应
      

  6.   

    jq 就简单多了$(function() {
      $(document).on('click', '[type=button]', function() {
        var that = this;
        $('[type=button]').each(function(i) {
          if(that == this) $('[type=text]').eq(i).focus();
        })
      })
    })