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粉8212313192023-10-13 16:06:26
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粉0900872282023-10-13 13:39:59
The default value of the
type< < 的默认值
is "submit". Set this to button
element's /code> attribute type="button"
to generate a button that does not submit the form.
<button type="button">Submit</button>
Using HTML standard words: "Do nothing."