I saw the implementation with the indication of confirm in the onclick event of the button, but I need to do this through the methods jquery and confirm should work to fulfill a certain condition. Is it possible to somehow implement?
2 answers
Sure you may. You should read the official jquery submit () documentation.
|
$(function(){ var a = 0; $('form').on('submit',function(e){ if (!a) { var confirmed = confirm('Отправить?'); if (!confirmed) e.preventDefault(); //Отменяем submit } a++; //Повторный submit отправит форму }) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="https://www.google.ru" method="get" target="submitted"> <input type="text" name="q"> <button> Submit </button> </form>
|