取得当前焦点所在的对象
document.activeElement

解决方案 »

  1.   

    <input name='ccc'>
    <input name='ccc'>
    <input name='ccc'>
    <br>
    下面这些是不知名的textbox<br>
    <input>
    <input>
    <input type=button value="赋值" onclick="var txtbox=document.getElementsByTagName('input');if(txtbox[3].type='text')txtbox[3].value='333'">
      

  2.   

    <input name='ccc'>
    <input name='ccc'>
    <input name='ccc'>
    <br>
    下面这些是不知名的textbox<br>
    <input>
    <input>
    <input type=button value="赋值" onclick="var txtbox=document.getElementsByTagName('input');if(txtbox[3].type=='text')txtbox[3].value='333'">
      

  3.   

    <input name='ccc'><br>
    <input name='ccc'><br>
    <input name='ccc'><br>
    <br>
    下面这些是不知名的textbox<br>
    <input><br>
    <input><br>
    <input><br>
    <input><br>
    <input><br>
    <input><br>
    <input type=button value="赋值" onclick="var txtbox=document.getElementsByTagName('input');for(i=3;i<txtbox.length;i++)if(txtbox[i].type=='text')txtbox[i].value=i;">
      

  4.   

    <input type=button value="赋值" onclick="var txtbox=document.getElementsByTagName('input');for(i=3;i<txtbox.length;i++)if(txtbox[i].type=='text')txtbox[i].value=i;">
    这样的话,是不管什么text框,都会有值了,我想只有那个有焦点的文本框才有值呀!!!
      

  5.   

    <html>
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
         function doClick(){
       var oldValue=document.activeElement.value;
       document.activeElement.value=oldValue+'aaaa';
     }
    //-->
    </SCRIPT>
       <form name="fm">
          <input type="text" name="a">
      <input type="text" name="b">
      <input type="text" name="c">
      <input type="button" value="ok" onclick="doClick();">
       </form>
    </body>
    </html>当我点击这个ok按钮时,我想把值附给当前获得焦点的text,但当我点的时候,焦点已经转到ok按钮上了,我不想转到ok按钮上,只想把值给获得焦点的text
      

  6.   

    是这个吗?
    <html>
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
         function doClick(){
       var oldValue=document.activeElement.value;
       document.fm.a.focus();
       document.activeElement.value=oldValue+'aaaa';
       
     }
    //-->
    </SCRIPT>
       <form name="fm">
          <input type="text" name="a">
      <input type="text" name="b">
      <input type="text" name="c">
      <input type="button" value="ok" onclick="doClick();">
       </form>
    </body>
    </html>
      

  7.   

    to andymu077(明治佐玛戒--秀曼) 
    不是。document.fm.a.focus();
    我是不知道这个a的.
      

  8.   

    <html>
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    document.onkeydown = dosave;
    var focusText;
    function dosave(){
       focusText = document.activeElement;
    }
    function doClick(){
       var oldValue=focusText.value;
       focusText.value=oldValue+'aaaa';
     }</SCRIPT>
       <form name="fm">
          <input type="text" name="a">
      <input type="text" name="b">
      <input type="text" name="c">
      <input type="button" value="ok" onclick="doClick();">
       </form>
    </body>
    </html>
      

  9.   

    暂时只好这样:
    <SCRIPT LANGUAGE="JavaScript">
    var lelement,flag=false;
    function doTrans(){
    if(flag){lelement.value="333333";flag=false;}
    }
    </SCRIPT>
    <input type="text" name="a" onblur="lelement=this;flag=true;">
    <input type="text" name="b"  onblur="lelement=this;flag=true;">
    <input type="text" name="c"  onblur="lelement=this;flag=true;"><input type="button" value="附值" onclick="doTrans();">
      

  10.   

    那就这么写?但是也要具体问题具体分析:
    <html>
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
         function doClick(){
       var oldValue=document.activeElement.value;
       document.fm.elements[0].focus();
       document.activeElement.value=oldValue+'aaaa';  }
    //-->
    </SCRIPT>
       <form name="fm">
          <input type="text" name="a">
      <input type="text" name="b">
      <input type="text" name="c">
      <input type="button" value="ok" onclick="doClick();">
       </form>
    </body>
    </html>
      

  11.   

    这样写!
    <input type="text" name="a">
    <input name="b">
    <input type="text" name="c"><input type="button" value="附值" onclick="doTrans('abcd');"><script language="javascript">
    document.onclick = foo;
    var el = null;function foo() {
      var t = event.srcElement;
      if(t.tagName == 'INPUT' && t.type == 'text')
        el = t;
    }function doTrans(value) {
      el.value = value;
    }
    </script>
      

  12.   

    <html>
    <body>
       <form name="fm">
          <input type="text" name="a">
      <input type="text" name="b">
      <input type="text" name="c">
      <input type="button" value="ok" onclick="doClick();">
       </form>
    </body>
    <SCRIPT LANGUAGE="JavaScript">
    var input = document.getElementsByTagName( "input" );
    var lastFocus;
    for(i=0;i<input.length;i++)
    {
    if( input[i].type == "text" )
    {
    input[i].onfocus=function(){
    lastFocus=this;
    }
    }
    }
    function doClick(){
       var oldValue=lastFocus.value;
       lastFocus.value=oldValue+'aaaa';
       lastFocus.focus();
     }</SCRIPT>
    </html>
      

  13.   

    <html>
    <head>
    <title>无标题</title>
    <head>
    <body><input type="text" id="a">
    <input type="text" id="b">
    <input type="text" id="c"><input type="text" id="d"><input type="button" value="附值" onmouseover="getobject()" onclick="setvalue();"><script language="javascript">
    var fromobject = null;
     
    function getobject()
    {//取得活动的对象
             fromobject = document.activeElement;
    }function setvalue()
    {
             //当点击按钮前的焦点是在a,b,c中任一个中时,就给该对象一个值,
             if(fromobject.id == "a" ||
                fromobject.id == "b" ||
                fromobject.id == "c" )
             {
               fromobject.value = "找到你了!";
             }
    }
    </script>
    </body>
    </html>
      

  14.   


    <input type="text" name="a" onclick="this.value='aaa'">
    <input type="text" name="b" onclick="this.value='bbb'">
    <input type="text" name="c" onclick="this.value='ccc'">
      

  15.   

    <html>
    <body>
       <form name="fm">
          <input type="text" name="a">
      <input type="text" name="b">
      <input type="text" name="c">
      <input type="button" value="ok" onclick="doClick();">
       </form>
    </body>
    </html>
    document.forms[0].elements[0].value=?;
    document.forms[0].elements[1].value=?;
    document.forms[0].elements[2].value=?;