Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the preventDefault () method in jQuery

Shulou Source: shulou.com Published: 2022-06-03 11:02:09 11月15日 Update

This article mainly introduces how to use the preventDefault () method in jQuery, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

The preventDefault () method prevents the default behavior of the element (for example, blocking the submission of the form when the submit button is clicked).

JQuery event-preventDefault () method example

Prevent links from opening URL:

$("a") .click (function (event) {

Event.preventDefault ()

})

E.preventDefault (); syntax

Event.preventDefault ()

Parameter description

Event is required. The default action that specifies which event to block. This event parameter comes from the event binding function.

First of all, the Table page, click the edit of one line, display the whole line of information on the Form form of the Modal page, directly cancel the Modal page, and click the edit of other lines again, the Form form of the Modal page can display the information of the new line normally.

However, if you click the submit button on the From form, close the Modal page, and then click another row edit, Modal's Form form still displays the previous line of information.

/ / submit

HandleSubmit= (e) = > {

E.preventDefault ()

This.props.form.validateFields ((err,values) = > {

/ / clear the default value of form

This.setState ({

MEMail:''

MPhone:''

MName:''

})

})

}

Although the Form content is cleared every time Modal is turned off, the default value of the printed Form is normal when it is displayed again.

But the previous message is on the page.

Finally, you choose to comment out e.preventDefault ();.

Thank you for reading this article carefully. I hope the article "how to use preventDefault () method in jQuery" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Forms methods information articles pages lines events again parameters buttons time values elements interests content functions actions and at the same time examples that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MySQL Shulou Tech Info MariaDB Microsoft