繁体   English   中英

确认框:单击“取消”按钮后,“确定”按钮不起作用

[英]Confirmation Box : OK button not working after clicking on Cancel Button

我有一个带有确认框的javascript函数。 单击按钮即可调用。 当我单击按钮时,出现带有“确定”和“取消”按钮的确认框。 如果我先单击“确定”,则其工作正常。 但是,当我单击“取消”,然后重新填充“确认”框并单击“确定”时,它不起作用。

的JavaScript

function Confirm() {
    var confirm_value = document.createElement("INPUT");
    confirm_value.type = "hidden";
    confirm_value.name = "confirm_value";
    if (confirm("Are you sure you want to cancel?")) {
        confirm_value.value = "Yes";
    } else {
        confirm_value.value = "No";
    }
    document.forms[0].appendChild(confirm_value);
}

纽扣

  <asp:Button ID="BtnCancelBooking" runat="server" Text="Cancel My Application" style="background-color:#5A105A;color:#ffffff" 
CssClass="FormsubmitButton" OnClientClick = "Confirm()"
  Width="140px" ValidationGroup="" Visible="True" />

VB代码:

 Protected Sub BtnCancelBooking_Click(sender As Object, e As System.EventArgs) Handles BtnCancelBooking.Click

    Dim confirmValue As String = Request.Form("confirm_value")
    If confirmValue = "Yes" Then


        Dim b As Boolean = objClsRoomBooking.CancelBooking(Convert.ToInt32(Session("AppID")), Convert.ToInt32(Session("StdYearID")), Convert.ToInt32(Session("ComID")))
        If b = True Then
            'ShowMessages(1, "Your Application has been Cancelled ")
            Response.Redirect("Details.aspx")
        Else
            ShowMessages(2, "Applicant Status has not been Cancelled")
        End If

    Else
          // else 
    End If
End Sub

每次您重新填充确认框,将函数更改为此时,您的代码都会向表单中添加重复的隐藏元素。

    function Confirm() {
        var tmpResp = "";
        if (confirm("Are you sure you want to cancel?")) {
            tmpResp = "Yes";
        } else {
            tmpResp = "No";
        }
        if(document.getElementById("confirm_value")) {
           document.getElementById("confirm_value").value = tmpResp;
        }
        else {
           var confirm_value = document.createElement("INPUT");
           confirm_value.type = "hidden";
           confirm_value.name = "confirm_value";
           confirm_value.id = "confirm_value";
           confirm_value.value= tmpResp;
           document.forms[0].appendChild(confirm_value);
        }
    }

此代码检查是否已存在hidden-field ,如果是,则向其分配confirm-box响应,否则创建新的hidden-field并将其追加到form 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM