确认框:点击取消按钮后,确定按钮不工作
Confirmation Box : OK button not working after clicking on Cancel Button
我有一个javascript函数与确认框。它被称为按钮点击。当我点击按钮,确认框与确定和取消按钮出现。如果我先点击OK,那么它工作得很好。但是当我点击取消,然后重新填充确认框,然后点击确定,它就不起作用了。
JavaScriptfunction 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);
}
<<p> 按钮/strong> <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
。
相关文章:
- Sencha Touch使一个简单的按钮工作
- Chrome扩展程序:浏览器操作单击按钮工作一次
- jquery如何让这个对话框的“确定”按钮工作
- 我的设备后退按钮工作不正常,它转到第一个html,但返回到第二个html
- 使“编辑”按钮工作
- 如何使单选按钮工作两个任务
- 通过输入键(不起作用)或搜索按钮(工作)查询结果
- 我有三个地方供用户登录,在同一页面上,我如何在一个功能中让所有三个按钮工作和三个表单处理
- 如果 ID 消失,提交按钮工作
- 无法让Gmail一键确认操作按钮工作
- 我无法使这些按钮工作
- 如何让我的离子侧菜单按钮工作
- 试图让按钮工作的功能,但我的警报弹出了书面脚本
- 一个按钮工作,其他不,相同的脚本
- 使用jquery ajax和PHP的浏览器“后退按钮”工作
- 在Firefox上禁用JavaScript意味着我的按钮不能工作,是否有一种方法可以让按钮工作?
- 按钮onclick按钮工作奇怪
- 在这种情况下,我如何使load more按钮工作
- 让我的后退和前进按钮工作与ajax
- 当在主干中使用推送状态重定向时,我如何保持“返回”?按钮工作