Javascript警报取消按钮在Safari

时间:2017-08-18 05:06:28

标签: javascript jquery html safari

我正在尝试设置一系列事件,以便当用户点击单选按钮时,它会触发要提交的表单。另外,我想给用户一个java警告,要求他们通过单击确定确认他们的选择,然后重定向到php页面,或者取消并保持当前页面并且什么也不做。这就是我所拥有的,但出于某种原因,当用户在safari中单击取消警报时,表单仍然会提交。

收音机onclick是否与实际脚本冲突?如何将警报添加到脚本?

<form name="confirmForm" id="confirmForm" method="POST" action="update_confirm.php">

<div id="confirmGroup">

<input type="radio" name="email_confirm" id="emailGroup1" value="Verify" class="verify" onclick="return confirm('Update Email Status?');" >
<label class="emailGroup" for="emailGroup1">Verify</label>

<input type="radio" name="email_confirm" id="emailGroup2" value="Good" class="good" onclick="return confirm('Update Email Status?');" >
<label class="emailGroup" for="emailGroup2">Good</label>

<input type="radio" name="email_confirm" id="emailGroup3" value="Bad" class="bad" onclick="return confirm('Update Email Status?');" >
<label class="emailGroup" for="emailGroup3">Bad</label>

</div>
</form>

-

<script> 
    $("#confirmForm").change(function()
    {
    document.getElementById("confirmForm").submit();
    });
</script>

2 个答案:

答案 0 :(得分:1)

您需要在JQuery confirm事件中添加change

$("#confirmForm").change(function() {
  if (confirm('Are you sure of your selection?')) {
    document.getElementById("confirmForm").submit();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="confirmForm" id="confirmForm" method="POST" action="update_confirm.php">

  <div id="confirmGroup">

    <input type="radio" name="email_confirm" id="emailGroup1" value="Verify" class="verify" onclick="return confirm('Update Email Status?');">
    <label class="emailGroup" for="emailGroup1">Verify</label>

    <input type="radio" name="email_confirm" id="emailGroup2" value="Good" class="good" onclick="return confirm('Update Email Status?');">
    <label class="emailGroup" for="emailGroup2">Good</label>

    <input type="radio" name="email_confirm" id="emailGroup3" value="Bad" class="bad" onclick="return confirm('Update Email Status?');">
    <label class="emailGroup" for="emailGroup3">Bad</label>

  </div>
</form>

答案 1 :(得分:0)

它在工作......

再次检查您的代码。

&#13;
&#13;
    $("#confirmForm").change(function()
    {
    document.getElementById("confirmForm").submit();
    });
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="confirmForm" id="confirmForm" method="POST" action="update_confirm.php">

<div id="confirmGroup">

<input type="radio" name="email_confirm" id="emailGroup1" value="Verify" class="verify" onclick="return confirm('Update Email Status?');" >
<label class="emailGroup" for="emailGroup1">Verify</label>

<input type="radio" name="email_confirm" id="emailGroup2" value="Good" class="good" onclick="return confirm('Update Email Status?');" >
<label class="emailGroup" for="emailGroup2">Good</label>

<input type="radio" name="email_confirm" id="emailGroup3" value="Bad" class="bad" onclick="return confirm('Update Email Status?');" >
<label class="emailGroup" for="emailGroup3">Bad</label>

</div>
</form>
&#13;
&#13;
&#13;