Home  >  Q&A  >  body text

Can I make the <button> not submit the form?

I have a form with 2 buttons

<a href="index.html"><button>Cancel changes</button></a>

<button type="submit">Submit</button>

I also used jQuery UI buttons on them, like this

$('button').button();

However, the first button also submits the form. I originally thought it wouldn't happen without type="submit".

Obviously I can do it

$('button[type!=submit]').click(function(event) { event.stopPropagation(); });

But is there a way to prevent the back button from submitting the form without JavaScript intervention?

To be honest, I just used a button so I could style it using jQuery UI. I tried calling button() on the link but it didn't work as expected (looked ugly!).

P粉921130067P粉921130067395 days ago449

reply all(2)I'll reply

  • P粉821231319
  • P粉090087228

    P粉0900872282023-10-13 13:39:59

    The default value of the

    type< < 的默认值button element's /code> attribute is "submit". Set this to type="button" to generate a button that does not submit the form.

    <button type="button">Submit</button>

    Using HTML standard words: "Do nothing."

    reply
    0
  • Cancelreply