<input type=text id="txt">
<input type=button id="go" value="go" onclick="alert('go')">
<script>
document.onkeydown=ShortcutKey; 
function ShortcutKey()  


if(window.event.keyCode==13)
{
go.focus();

}

}
   
</script>

解决方案 »

  1.   

    我就想在上面那个文体框中利用onkeypress的属性,然后判断键值是否是回车,然后去执行那个saveChanges,或者就干脆不动.请给我一个指点.谢谢.
      

  2.   

    刚才在找了个例子如下.
    <html>
    <body>
    <script>
    function start(){alert('fk')}
    function document.body.onkeypress(){
     if(event.keyCode==13)
      start();
     }
    </script><input type="text" name="br1" size="3">
    </input>
    <button onclick="start()" accesskey="s">Start</button> 
    </body>
    </html>
    这个例子中点击回车就可以做一个我想要的动作.按这个思路我重新做了一下改变如下,可是还是没我想要的结果.
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Flash Time Setting</title>
    </head>
    <body topmargin="45" leftmargin="80">
    <Script language="JavaScript">
    function isNumeric(str,small,max)
    {  
          if (!isNaN(str) && str >= small && str <= max){
            return true
          }
          return false      
    }
    function saveChanges()
    {      
          if (!(isNumeric(document.flashform.FTime1.value,4,255)))
          {
             alert('The Max Flash Time value should be between 4 and 255 ! ');
             document.flashform.FTime1.value=document.flashform.FTime1.defaultValue;
             document.flashform.FTime1.focus();         
           return false;
          }   
          document.flashform.FTime1.value=parseInt(document.flashform.FTime1.value,10);   
          alert('the value is : '+document.flashform.FTime1.value);
          return true;
    } function doit()
    {
    alert("do it");
    }
    function document.flashform.FTime1.onKeyPress()
    {
    if(event.KeyCode==13) doit();
    }
    </Script>
    <p><font face="Times New Roman" size="6" color="#000080">Flash Time Setting</font></p>
    <table border="0" width="500" id="table1">
    <tr>
    <td><font face="Arial" size="2">You could set the flash time in this 
    page.</font></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    </table><table border="0" width="500" id="table2">
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>
    <form   name="flashform">
    <table border="0" width="100%" id="table3">
    <tr>
    <td width="27%" bgcolor="#000080">
    <font face="Arial" size="2" color="#FFFFFF">Max Flash Time:</font></td>
    <td width="71%" bgcolor="#000080">
    <font size="2" face="Arial" color="#FFFFFF">&nbsp;<!--t1--><input type="text" name="FTime1" size="3" value="134" maxlength="3"> 
    x 10MS (4~255)</font></td>
    </tr>
    <tr>
    <td width="145">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td width="145">&nbsp;</td>
    <td>&nbsp;<input type="submit" value="Submit" name="Apply" onClick="return saveChanges()" >&nbsp;
    <input type="reset" value="Reset" name="Clear"></td>
    </tr>
    </table><p>&nbsp;</p>
    </form>
    <p>&nbsp;</td> </tr></table>


    </body>
    </html>
    请问各位高人,我该如何做呢?再一次表示感谢.谢谢.
      

  3.   

    <html>
    <body>
    <input type=text id="txt" NAME="txt" onkeypress="ShortcutKey();">
    <input type=button id="go" value="go" onclick="alert('go')" NAME="go">
    </body>
    </html>
    <script language=javascript>function ShortcutKey()  
    {  if(window.event.keyCode==13)
    {
    go.click(); }}
    </script>
      

  4.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Flash Time Setting</title>
    </head>
    <Script language="JavaScript">
    function isNumeric(str,small,max)
    {  
          if (!isNaN(str) && str >= small && str <= max){
            return true
          }
          return false      
    }
    function saveChanges()
    {      
          if (!(isNumeric(document.flashform.FTime1.value,4,255)))
          {
             alert('The Max Flash Time value should be between 4 and 255 ! ');
             document.flashform.FTime1.value=document.flashform.FTime1.defaultValue;
             document.flashform.FTime1.focus();         
           return false;
          }   
          document.flashform.FTime1.value=parseInt(document.flashform.FTime1.value,10);   
          alert('the value is : '+document.flashform.FTime1.value);
          return true;
    }</Script>
    <body topmargin="45" leftmargin="80">
    <p><font face="Times New Roman" size="6" color="#000080">Flash Time Setting</font></p>
    <table border="0" width="500" id="table1">
    <tr>
    <td><font face="Arial" size="2">You could set the flash time in this 
    page.</font></td>
    </tr>
    <tr>
    <td><hr></td>
    </tr>
    </table><table border="0" width="500" id="table2">
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>
    <form  method="POST" action=/flashset.cgi name="flashform">
    <table border="0" width="100%" id="table3">
    <tr>
    <td width="27%" bgcolor="#000080">
    <font face="Arial" size="2" color="#FFFFFF">Max Flash Time:</font></td>
    <td width="71%" bgcolor="#000080">
    <font size="2" face="Arial" color="#FFFFFF">&nbsp;<!--t1--><input type="text" name="FTime1" size="3" value="134" maxlength="3" onKeyDown="if(event.keyCode==13) return saveChanges()"> 
    x 10MS (4~255)</font></td>
    </tr>
    <tr>
    <td width="145">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td width="145">&nbsp;</td>
    <td>&nbsp;<input type="submit" value="Submit" name="Apply" onClick="return saveChanges()" >&nbsp;
    <input type="reset" value="Reset" name="Clear"></td>
    </tr>
    </table><p>&nbsp;</p>
    </form>
    <p>&nbsp;</td></tr></table>
    </body>
    </html>
      

  5.   

    主要改动
    <input type="text" name="FTime1" size="3" value="134" maxlength="3" onKeyDown="if(event.keyCode==13) return saveChanges()"> 加了一个onkeydown的判断
      

  6.   

    event.KeyCode==13不对,
    应该是event.keyCode==13
    注意大小写。另外,你直接这样写function document.flashform.FTime1.onKeyPress()不行吧,在加载script的时候,flashform还没有生成,会出找不到对象的错误。
    function test()
    {
    if(event.KeyCode==13) doit();
    }<input type="text" name="FTime1" size="3" value="134" maxlength="3" onkeypress="test()"> 这样试试
      

  7.   

    ie的一个bug(也有可能是一种自作聪明的功能)
    当页面form只有一个text-input时,回车就会将这个form submit.JK常用的解决方法:
    在form 里加一个:<input style="display:none;"/>
      

  8.   

    好像多个text的时候回车也是submit吧
      

  9.   

    还会提交是因为有个submit的按钮。
    加个text-input后,就会先执行submit按钮的onclick事件,
    如果不加的话,不会执行submit的onclick事件,(应该也不会触发form的onsubmit)
      

  10.   

    今天一天太多事,都没有来的及上来看看,十分感谢各位大侠的热忱和指导,没想有这么的高人来给在下指点,先行谢过,祝各位身体健康,万事如意.
    中午在不经意间,给后面多加了个text如下:
    <form  method="POST" action=/flashset.cgi name="flashform">
    <table border="0" width="100%" id="table3">
    <tr>
    <td width="27%" bgcolor="#000080">
    <font face="Arial" size="2" color="#FFFFFF">Max Flash Time:</font></td>
    <td width="71%" bgcolor="#000080">
    <font size="2" face="Arial" color="#FFFFFF">&nbsp;<!--t1--><input type="text" name="FTime1" size="3" value="134" maxlength="3" onKeyDown="if(event.keyCode==13) return saveChanges()"> 
    x 10MS (4~255)</font></td>
    </tr>
    <tr>
    <td width="145">&nbsp;</td>
    <td>&nbsp;<input type=\"HIDDEN\" name=\"aaa\"></td>
    </tr>
    <tr>
    <td width="145">&nbsp;</td>
    <td>&nbsp;<input type="submit" value="Submit" name="Apply" onClick="return saveChanges()" >&nbsp;
    <input type="reset" value="Reset" name="Clear"></td>
    </tr>
    </table><p>&nbsp;</p>
    </form>
    这是不是就是如各位高人们所说的那样的解决办法呢?感谢高人们对执行机理的讲解,谢谢.