How to disable the "submit" behavior of a button label inside a form label?
P粉461599845
P粉461599845 2023-08-24 15:00:36
0
2
426
<p><pre class="brush:php;toolbar:false;"><form action=""> <button>click</button> </form></pre> The default behavior of the <p> button within a form is to submit the form. </p> <p>How do I disable the submit behavior of this button? </p>
P粉461599845
P粉461599845

reply all(2)
P粉714844743

Sometimes you want to preserve the details of a submit button (for example, on mobile devices, the button can only be accessed via the keyboard if it is part of a form and of type submit Trigger submit button). In this case, you need to prevent the button's default behavior.

Using jQuery 1.7 (using .on - I highly recommend reading the documentation - there are many nuances to using .on that can greatly impact performance)

$(document).on("click", "button", "event", function(evt) {
    evt.preventDefault();
    ...
}

Using an older version of jQuery...

$("#button-id").bind("click", function(evt, ui) {
    evt.preventDefault();
    ...
}

Please note that you can use any selector (select by class, element type, etc.) or method of binding an event (instead of using .bind, use whatever works for you jQuery versions of .live, .delegate, etc.).

P粉238355860

Add type="button" above it:

<button type="button">Click</button>

Available types are:

  • "submit": Default value. submit Form.
  • "reset": Reset the input of the form.
  • "button": No operation.

A good reference: https://developer.mozilla.org/en/DOM/HTMLButtonElement

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!