有两个input,第一个输入的是十个数字,第二个input自动获得第一个的后六位,当光标移动到第二个input时,自动输入获得的后六位,应该怎么实现?

解决方案 »

  1.   

    <input type="text" id="a" />
    <input type="text" id="b" />
    window.onload = function() {
      var b = document.getElementById("b");
      b.focus = function() {
          var a = document.getElementById("a").value;
          a = a.substring(a.length - 6 - 1, a.length);
          b.value = a; 
     };
    };
      

  2.   


    window.onload = function() {
      var b = document.getElementById("b");
      b.onfocus = function() {
          var a = document.getElementById("a").value;
          a = a.substring(a.length - 6 - 1, a.length);
          b.value = a; 
     };
    };
      

  3.   


    <body>
    <input type="text" id="f" />
    <input type="text" id="s" />
    <script>
    window.onload = function() {
    var f = document.getElementById('f'),
    s = document.getElementById('s');
    s.onfocus = function() {
    this.value = f.value.slice(-6);

    }
    </script>
    </body>
      

  4.   

    献个丑。jQuery实现
    <html>
    <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $().ready(function(){
        $('#b').focus(function(event){
            $('#b').val($('#a').val().substring(5));
        });
    });
    </script>
    </head><body>
    <input type="text" id="a" value="input abc 1234"/>
    <input type="text" id="b" />
    </body>
    </html>
      

  5.   


     function pass() {
       var b = document.getElementById("password");
       b.onfocus = function() {
           var a = document.getElementById("no").value;
           a = a.slice(4);
           b.value = a;