Confirm before a form submit

前端 未结 7 1344
孤城傲影
孤城傲影 2020-12-05 07:38

I have searched for an answer but couldn\'t find one!

I have a simple form,

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 08:18

    HTML:

    
        
    
    

    JavaScript:

    var el = document.getElementById('myCoolForm');
    
    el.addEventListener('submit', function(){
        return confirm('Are you sure you want to submit this form?');
    }, false);
    

    Edit: you can always use inline JS code like this:

提交回复
热议问题