本帖最后由 www_vane 于 2009-07-09 22:23:53 编辑

解决方案 »

  1.   

    if(event.keyCode==13) document.getElementById("btn").onclick();
    这个样子必须行哦...是不是哪里有错误?
      

  2.   

    无论又没有submit按了enter都会默认提交啊
      

  3.   

    没有submit只有button
    按了enter后是不会提交的哦..
      

  4.   

    onload="if(event.keyCode==13) document.getElementById("btn").onclick();"
    这样还是无显示哦..
    在id="btn"的onclick="fun1()"
    fun1()
    {
       document.write();
    }
    ?????
      

  5.   

    document添加onkeydown监听<form method='get'>
    <input type='text' name='frm1' value='frm1'/>
    </form>
    <form method='get'>
    <input type='text' name='frm2' value='frm2'/>
    </form>
    <script>
    document.onkeydown=function(e){
      e=e||event;
      if(e.keyCode!=13)return false;//不是enter键退出
      var o=e.target||e.srcElement;
      while(o){//判断当前元素及父亲元素是否为表单
        if(o.tagName=="FOMR")o.sumbit();
        else o=o.parentNode;
      }
    }
    </script>
      

  6.   

    -.=!我说的是form中没有submit
    只有button
    但是当我们按取了enter后仍然可以实现提交
    我如果在button中加个onclick
    onload="if(event.keyCode==13) document.getElementById("btn").onclick();" 
    这样还是无显示哦.. 
    在id="btn"的onclick="fun1()" 
    fun1() 

      document.write(); 

    还是不行哦...哎....
      

  7.   

    对不住楼上的各位
    我的编辑器出问题了
    导致各位给的正确代码及正确提示在我这里无法显示
    非常感谢7L
    还有三L的提醒!!
    下面是我实施的3L代码
    <html>
    <head>
    <title></title>
    <Script language="JavaScript">
    function fun1()
    {
    if(event.keyCode==13) 
    document.getElementById("btn").onclick();
    }
    function fun2()
    {
    w=document.getElementById("txtN").value;
    document.write(w);
    }
    </Script>
    </head>
    <body onload="fun1()">
    <input type="text" id="txtN"/>
    <input type="button" id="btn" value="提交" onClick="fun2()"/>
    </body>
    </html>