我正在使用 jQuery 和 PHP 的组合,但我对 jQuery 方面有疑问。
我有一个具有不同选项的选择,所有这些选项都有不同的确认()和不同的提交表单。
我已经添加了onclick:
<option value="CANCEL" onclick="return confirm('Are you sure you want to cancel the claim?'); $('#CANCEL').submit();">Cancel Claim</option>
但是我只是收到确认消息,如果我单击"is",则不会提交表单。
我想我需要提前做一些事情来将confirm()和submit()联系在一起。有什么想法吗?
下面是一个片段
<select name="CLAIM_ACTION" style="text-align:center; float:right; margin: 0px 10px 0px 0px;">
<option value="">Select an Action</option>
<option value="CANCEL" onclick="return confirm('Are you sure you want to cancel the claim?'); $('#CANCEL').submit();">Cancel Claim</option>
<option value="CLOSE" onclick="return confirm('Are you sure you want to close the claim?');" >Close Claim</option>
<option value="WOFF" onclick="return confirm('Are you sure you want to write off the claim?');">Write Off</option>
<option value="REOPEN" onclick="return confirm('Are you sure you want to re-open the claim?');">Re-open Claim</option>
</select>
<form name="CANCEL" action="claims.php?claimID=<?php echo $claim; ?>&claimTab=Info" method="post">
<input type="text" name="CANCELVALUE" value="CANCEL" hidden />
</form>
最佳答案
你可以尝试 -
<option value="CANCEL" onclick="check_confirmed()">Cancel Claim</option>
还有
function check_confirmed()
{
if(confirm('Are you sure you want to cancel the claim?')) {
$('#CANCEL').submit();
} else {
return false;
}
}
关于javascript - 如何在一次 onclick 中运行确认()和提交(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36153496/