Jquery Ajax简单形式annot获取表单以停止使用<enter>提交

时间:2016-02-13 03:38:46

标签: php jquery ajax forms

这让我疯了。 无论我做什么,无论何时在任何表单字段中输入,我都无法保持此Ajax JQuery表单的提交。

我一直在寻找论坛,似乎没有任何建议有所帮助。我正在刷新我的浏览器窗口,我认为它会刷新所有代码,但这很疯狂。

请帮忙!     

<title>555</title>
<!-- jQuery --> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<!-- The Ajax Submit Script -->
    <script>
      $(function () {


        $('#msform').submit(function(e){

          e.preventDefault();

          $.ajax({
            type: 'post',
            url: 'assets/upload.php',
            data: $('#msform').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });
            return false;  
        });

      });   
    </script>


</head>
<body>


<!-- start error message div -->
<div id="form-messages"></div>
<!-- end error message div -->

<!-- multistep form -->
<form id="msform" name="msform">
    <fieldset>
        <h2 class="fs-title">Submit This</h2>
        <h3 class="fs-subtitle">heidiho neighbor!</h3>
        <input type="text" name="website" placeholder="Website" />
        <table>
            <tr>
                <td><input type="text" name="firstname" placeholder="First Name" /></td>
                <td><input type="text" name="lastname" placeholder="Last Name" /></td>
            </tr>
        </table>    
        <input type="text" name="email" placeholder="Email" />
        <input type="text" name="phone" placeholder="Phone" />
        <input type="submit" value="submit" id="submit"/>
    </fieldset>
</form>

1 个答案:

答案 0 :(得分:-1)

我认为你需要在文本框上捕获Enter键并在找到时禁用它们。

$(":text").keydown(function(e){
    if(e.which==13)
    {
        return false;
    }
});