[英]How to call a confirm function before submitting a form only on click of one submit button not on the other submit button present?
我有以下表单布局:
<form action="newsletter.php" name="newsletter" id="newsletter" method="post">
<input type="submit" value="Submit" class="c-btn" id="submit_value" name="submit_value">
<input type="submit" value="Send" class="c-btn" id="send_value" name="send_value">
</form>
点击标题为发送 jQuery警报的按钮时,应该询问“你确定要发送邮件吗?”。
如果用户点击“是”,那么表单应该提交,如果用户点击“否”,则表单不应该提交。
当用户点击提交值为“提交”的提交按钮时,不应该发出此警报,表单应该正常提交。
我怎样才能做到这一点 ?
<form action="newsletter.php" name="newsletter" id="newsletter" method="post">
<input type="submit" value="Submit" class="c-btn" id="submit_value" name="submit_value" onclick="return confirm('Are you sure to send the mail?');">
<input type="submit" value="Send" class="c-btn" id="send_value" name="send_value">
</form>
使用这样的,因为你只想在点击发送按钮时使用onclick而不是在发送按钮上的onSubmit上显示确认
<form action="newsletter.php" name="newsletter" id="newsletter" method="post">
<input type="submit" value="Submit" class="c-btn" id="submit_value" name="submit_value">
<input type="submit" value="Send" class="c-btn" id="submit_value" name="submit_value" onclick="if(!confirm('Are you sure to send the mail?')){return false;}">
</form>
javascript confirm
函数返回boolean
,因此您可以将其添加到要确认操作的input
中
return confirm('are you sure ?');
就像这样
<form action="newsletter.php" name="newsletter" id="newsletter" method="post" onsubmit="">
<input type="submit" value="Submit" class="c-btn" id="submit_value" name="submit_value">
<input type="submit" value="Send" class="c-btn" id="send_value" name="send_value" onclick="return confirm('are you sure ?');">
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.