对于一个带有询问是否正确填写字段的警报的简单表单,我需要一个执行此操作的函数:
点击按钮时显示一个警告框,有两个选项:
我认为 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>
最佳答案
一个简单的内联 JavaScript 确认就足够了:
<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);">
https://stackoverflow.com/questions/6515502/