Can I make the <button> not submit the form?
P粉921130067
P粉921130067 2023-10-12 17:04:23
0
2
489

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粉921130067
P粉921130067

reply all(2)
P粉821231319

button The default type of element a> is submit.

You can make it do nothing by setting the button type:

<button type="button">Cancel changes</button>
P粉090087228

The default value of the

typebutton 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."

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template