按enter提交表单是默认的,都这样的应该.

解决方案 »

  1.   

    <!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 runat="server">
        <title>无标题页</title>
    </head>
    <body onkeydown="bodyKeyDown(event)" onload="focusInput()">
        <form id="form1" runat="server">
            <div>
                <input type="text" id="txt1" />
            </div>
        </form>
    </body>
    </html>
    <script type="text/javascript">    function bodyKeyDown(e)
        {
           var kc=e.keyCode;
           if(kc==32)
           {
            focusInput();
           }
           else if(kc==13)
           {
            document.form1.submit();
           }
        }
        
        function focusInput()
        {
            document.getElementById('txt1').select();
            document.getElementById('txt1').focus();
        }
        
        
        </script>
      

  2.   

    谢谢avon520了,但是按下空格键时候老是有空格出现,怎样让不出现空格啊.
      

  3.   

    就是说按space后txt有个空格键,怎样不要出现啊.
      

  4.   

    你 按下空格后,  把你的事件 执行过后,再 把txt的空格截取掉就行了
      

  5.   

    function focusInput()
        {
            document.getElementById('txt').select();
            document.getElementById('txt').focus();
            document.getElementById('txt').value='';
        }
    这样不行啊.....