JavaScript表单提交-确认或取消提交对话框对于具有询问字段是否正确填写的警报的简单表单,我需要一个这样做的函数:使用两个选项单击按钮时显示一个警告框:如果单击“确定”,则提交表单。如果单击“取消”,则“警报”框将关闭,并可对窗体进行调整和重新提交。我认为JavaScript确认会起作用,但我似乎不知道怎么做。我现在的代码是:function show_alert() { alert("xxxxxx");}<form> <input type="image" src="xxx" border="0" name="submit" onclick="show_alert();" alt="PayPal - The safer, easier way to pay online!" value="Submit"></form>
3 回答
largeQ
TA贡献2039条经验 获得超7个赞
<form onsubmit="return confirm('Do you really want to submit the form?');">
<script>function validate(form) { // validation code here ... if(!valid) { alert('Please correct the errors in the form!'); return false; } else { return confirm('Do you really want to submit the form?'); }}</script><form onsubmit="return validate(this);">
qq_笑_17
TA贡献1818条经验 获得超7个赞
function show_alert() { if(confirm("Do you really want to do this?")) document.forms[0].submit(); else return false;}
蓝山帝景
TA贡献1843条经验 获得超7个赞
好的,
<script>function submit() { return confirm('Do you really want to submit the form?');}</script><form onsubmit="return submit(this);"> <input type="image" src="xxx" border="0" name="submit" onclick="show_alert();" alt="PayPal - The safer, easier way to pay online!" value="Submit"></form>
function submitForm() { return confirm('Do you really want to submit the form?');}
<form onsubmit="return submitForm(this);"> <input type="text" border="0" name="submit" /> <button value="submit">submit</button></form>
添加回答
举报
0/150
提交
取消