How to use .preventDefault() method to prevent button click event
P粉254077747
P粉254077747 2023-09-01 20:04:07
0
2
441

Given this tutorialhttps:// vuejs.org/guide/essentials/event-handling.html#accessing-event-argument-in-inline-handlers

In the code shown below, I call .preventDefault to expect the normal behavior of canceling the click event. Or in other words, I expect that once .preventDefault is called, the button will no longer be clickable because from my understanding, .preventDefault will disable the button's normal functionality .

But what happens is that the button is still clickable, as if .preventDefault has no effect.

Please tell me how to properly use .preventDefault to disable button clicks.

Code:

  

P粉254077747
P粉254077747

reply all (2)
P粉002023326

preventDefault is useful in the following situations:

  • Prevent form submission when clicking the "Submit" button
  • When a link is clicked, prevent the link from jumping to the URL

To disable the button in your case you can use:

const warn = (msg,DOMEvent) => { DOMEvent.srcElement.disabled = true; }
    P粉726234648

    preventDefault()will not disable the button, but will prevent its default action, which will be mainly noticed in theSubmitaction.
    To disable a button on click, you need to do something like this:

      
      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!