Confirm before a form submit

前端 未结 7 1341
孤城傲影
孤城傲影 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:34

    var submit = document.querySelector("input[type=submit]");
      
    /* set onclick on submit input */   
    submit.setAttribute("onclick", "return test()");
    
    //submit.addEventListener("click", test);
    
    function test() {
    
      if (confirm('Are you sure you want to submit this form?')) {         
        return true;         
      } else {
        return false;
      }
    
    }
    
      
    

提交回复
热议问题