本帖最后由 shangqiu2012cs 于 2014-02-17 15:53:34 编辑

解决方案 »

  1.   

    <form action="1.html" method='get' id='xx'> <input>
    </form> <script>
    function init() {
    function keydownFn(e) {
    if(e.which===13){
    e.preventDefault();
    }
    }
    var $f = document.getElementById('xx');
    $f.addEventListener('keydown', keydownFn);
    }
    init();
    </script>
      

  2.   

    event.preventDefault ? event.preventDefault() : event.returnValue = false;
      

  3.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <form action="1.html" method='get' id='xx'>
     
            <input>
     
     
     
     
        </form>
     
        <script>
            function init() {
                document.getElementsByTagName('input')[0].onkeydown=function(e){
    var a=e||window.event;
    if(a.preventDefault){
    a.preventDefault();
    }else{
    a.returnValue=false;
    }
    }
            }
           init();
        </script>
    </body>
    </html>试了下可以 是不是你哪里写错了啊
      

  4.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <form action="1.html" method='get' id='xx'>
     
            <input>
     
     
     
     
        </form>
     
        <script>
            function init() {
                document.getElementsByTagName('input')[0].onkeydown=function(e){
    var a=e||window.event;
    if(a.keyCode==13){
    if(a.preventDefault){
    a.preventDefault();
    }else{
    a.returnValue=false;
    }
    }
    }
            }
           init();
        </script>
    </body>
    </html>
    facuo le 
      

  5.   

    <form action="" method="post" onsubmit="return check();">
    <input type="text" value="" id="sbox"/>
    </form>
    <script src="jquery.min.js"></script>
    <script>
    $(function(){
    $("#sbox").keydown(function(event){
    if(event.keyCode==13)
    {
    return false;//event.preventDefault();

    }
    });

    });
    function check()
    {
    alert('提交');
    }
    </script>
      

  6.   

    event.preventDefault(); 或者return false都可以的
      

  7.   

    document.getElementById("searchName").onkeydown = function()
    {
        if(event.keyCode == 13)
        {
           document.getElementById("search").click(); ----尼玛,问题就是这一句 
           event.returnValue = false;
           event.keyCode  = 0 ;
        }
    }上面不执行document.getElementById("search").click()表单提交就可以被阻止,可是这一句必须要有哇!这可怎么办!
      

  8.   

    靠,又发现另外一个问题:chrome下keyCode的值不可写!
      

  9.   

    我靠靠靠,你就不会放到后面的吗?
    <form action="1.html" method='get' id='xx'> <input>
    <input type='submit' id='search'> </form> <script>

    function init() {
    function keydownFn(e) {
    if(e.which===13){
    e.preventDefault();
    var $a = document.getElementById("search");
    $a.click();
    }
    }
    var $f = document.getElementById('xx');
    $f.addEventListener('keydown', keydownFn);
    }
    init();
    </script>是event不可写。
      

  10.   

    哥,相信我,这样也试过了,还是没用的!
    event不可写? 原来是这样!!!
      

  11.   

    转是因为
     var $a = document.getElementById("search");
                        $a.click();
    我就不明白你为什么要它click.  
      

  12.   

    回车已阻止。
    <input type='button' id='search'>   click这,有没有默认动作?
    <input type='submit' id='search'>   click 这就会执行submit动作。
      

  13.   

    我发现是document.getElementById("search").click()这里面的alert语句的问题
    document.getElementById("searchName").onkeydown = function()
    {
        if(event.keyCode == 13)
        {
           alert("请输入您要搜索的规则名称!"); ----这里,只要是alert语句,就会表单提交,语句移到后面也
                                                    是一样 
           event.returnValue = false;
           event.keyCode  = 0 ;
        }
    }
    因为window.event是全局唯一的,我猜想,会不会是alert语句弹出对话框之后,我点击时,产生了一个新的event,原来的被修改了.
    可是在alert语句前后查看event,好像也没有变化!
    神啊,这到底是怎么回事!
      

  14.   

    1. 你的 click 是什么页面导致一定需要调用?
    2. 在submit 的 标签上  加上 onclick="return false;" 当确定要提交时再修改它的onclick