prevent refresh of page when button inside form clicked

前端 未结 13 1883
终归单人心
终归单人心 2020-11-22 04:58

I have an issue while using buttons inside form. I want that button to call function. It does, but with unwanted result that it refresh the page.

My simple code goes

13条回答
  •  伪装坚强ぢ
    2020-11-22 05:21

    A javascript method to disable the button itself

    document.getElementById("ID NAME").disabled = true;
    

    Once all form fields have satisfied your criteria, you can re-enable the button

    Using a Jquery will be something like this

    $( "#ID NAME" ).prop( "disabled", true);
    

提交回复
热议问题