简体   繁体   English

提交按钮不会触发表单提交

[英]Submit button isn't triggering form submit

I have this html form for which the submit button has some weird behavior. 我有此html表单,其提交按钮具有一些奇怪的行为。

When I click the Submit button it stays depressed, but it does not submit the form. 当我单击“提交”按钮时,它保持按下状态,但不提交表单。 However, if the form is submitted by other means, say pressing Enter on the keyboard, or GO on Mobile Safari (iDevice), everything works fine. 但是,如果通过其他方式提交表单,例如在键盘上按Enter ,或者在Mobile Safari(iDevice)上按GO ,则一切正常。 I am using jQuery mobile btw. 我正在使用jQuery mobile btw。

Can anyone see why this might be the case? 谁能看到为什么会这样吗?

HTML 的HTML

<div class='login' id='login'>
    <div class='login-header'>Please Login</div>
    <div class='alert-error' id='login-error' style='display:none;'>
      Please check your username and password and try again.
    </div>

    <form id='login_form'>
      <br>
      <p class='label'>Username</p>
      <input type='text' name='username'>
      <p class ='label'>Password</p>
      <input type='password' name='password'>
      <button type='submit' data-theme='a' id='login-button'>Login</button> 
    </form>
  </div>

JS JS

$('#login_form').submit(function(e) {
        e.preventDefault();
        e.stopPropagation();

        var serializedFormData = $(this).serialize();

        // blah blah ajax form submit
        });
    });

EDIT 编辑

It seems like I was able to solve my problem by switching the following lines: 看来我可以通过切换以下行来解决我的问题:

<button type='submit' data-theme='a' id='login-button'>Login</button> 

with

<input type='submit' value='Submit'>.

Reputation remains to be awarded to anyone who knows why this worked. 声誉仍将授予任何知道其行之有效的人。

Try removing e.preventDefault(); 尝试删除e.preventDefault(); and see if the button is working. 并查看按钮是否正常工作。

Try 尝试

  $('#login_button').click(function(e) {
    e.preventDefault();

    var serializedFormData = $('#login_form').serialize();

    // blah blah ajax form submit
    });
});

This is how I submit my forms using ajax, pressing return still works as expected 这就是我使用ajax提交表单的方式,按return仍然可以正常工作

There's no <button type="submit">Submit me</button> . 没有<button type="submit">Submit me</button>

Submit button should actually be an input tag with type="submit" 提交按钮实际上应该是type="submit"input标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM