HTML form confirmation


When submitting the form, for some important operations, we need to give the user some prompts to let the user confirm their operation, to prevent the user from operating due to some accidents. For example, when deleting information, it is necessary to give the user some prompts. Here is a simple prompt operation of a form form:

HTML file, the important thing here is the onsubmit attribute, which specifies the JavaScript (required) to be executed when the form submission event occurs. When there is a method to return a value, false is returned, the form is not submitted, and true is submitted.
<form th:action="@{/home/deleteTeam}" onsubmit="return toVaild()" method="post">
    <button id="btn_submit" class="btn-danger" type="submit">删除</button>  
</form>
js code
    <script>
        function toVaild(){
    
    
            return confirm("确定删除?")
        }
    </script>

When you click Submit, it will have a pop-up prompt, you confirm that it will submit the form, click Cancel, it will not submit.
In this way, the prompt effect is achieved.

Guess you like

Origin blog.csdn.net/weixin_43520670/article/details/112134724