<p>
  一 <input type="text" name="textfield" />
  <input type="submit" name="Submit" value="提交" />
</p>
<p>
  二 <input type="text" name="textfield2" />
  <input type="submit" name="Submit2" value="提交2" />
</p>
如何在输入下面的文本框的时候,按回车键相应 提交2?

解决方案 »

  1.   

    同属于一个form,要提交就得一起提交,或者你可以用ajax post
    onkeydown,然后判断event的keyCode,等于13表明按下的是回车键。
      

  2.   


    <!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD  HTML  4.01  Transitional//EN">
      <html>
      <head>
      <meta  http-equiv="Content-Type"  content="text/html;  charset=gb2312">
      <title>a.htm </title>
      <script>
    document.onkeydown=function()              //网页内按下回车触发
    {
            if(event.keyCode==13)
            {                document.getElementById("bbb").onclick();   
                    return false;                               
            }
    }
      </script>
      </head>  <body>
    <form name=form1>
      <input type="text" value=""  id="aaa"  name="aaa"  onclick="alert('1提交')">
      <input type="button" value=""  id="bbb"  name="bbb"  onclick="alert('2提交')">
    </form>
      </body>
      </html>
      

  3.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD><BODY>
    <form id='test' action="http://www.baidu.com">
    <input type="text">
    <input type="text">
    </form>
    <script>
    var $ = function(id){return document.getElementById(id)}
    $('test').onkeypress = function(event){
    var event = event||window.event
    if(event.keyCode==13){
    $('test').submit();
    }
    }
    </script>
    </BODY>
    </HTML>
      

  4.   

    在input框中,是以submit函数作为提交的。不会触发其他按钮的事件。
      

  5.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
     </head> <body>
    <form name="form1" action="http://www.baidu.com">
      <input type="text" name="textfield" /> 
      <input type="submit" name="Submit1" id="Submit1" value="提交" /> 
    </p> 
    </form><form name="form1" action="http://www.google.cn">
    <p> 
      <input type="text" name="textfield2" /> 
      <input type="submit" name="Submit2" id="Submit2" value="提交2" /> 
    </p> 
    </form>
    <script type="text/javascript">
    <!--
    document.onkeydown = function(e){
    var e = e || window.event;
    if(e.keyCode == 13){
    document.getElementById("Submit2").click();
    }
    }
    //-->
    </script>
      
     </body>
    </html>