javascript - JavaScript 确认 OK 按钮不调用服务器端方法
问题描述
确认好的按钮不起作用,它没有调用服务器端方法。
按钮被禁用,但未调用服务器端功能。
如果我从确认方法中删除以下两行,那么它工作正常;
document.getElementById('btnSubmit').disabled = true;
document.getElementById('btnCancel').disabled = true;
代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript">
function confirmPayment() {
var isOkay = confirm("Confirm Payment?");
if (isOkay) {
document.getElementById('btnSubmit').disabled = true;
document.getElementById('btnCancel').disabled = true;
return isOkay;
} else {
return isOkay;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnSubmit" runat="server" Width="110px" OnClientClick="return confirmPayment();"
Text="Submit Payment" ></asp:Button>
<asp:Button ID="btnCancel" runat="server" Width="110px"
Text="Cancel" CausesValidation="False"></asp:Button>
</div>
</form>
</body>
有什么想法吗 ?
解决方案
我建议您设置控件 ClientIDMode="Static" 以防万一。
如果你不这样做,那么你应该采用这种格式:
var btn = document.getElementById('<%=Button1.ClientID%>');
或者在你的情况下:
document.getElementById('<%=btnSubmit.ClientID%>).disabled = true;
推荐阅读
- swift - 当图像点击全屏时,我想做一个 if 语句
- python - 当文件名是python中的变量时,如何更改文件名的一部分?
- amazon-web-services - AWS SAM 包不发送到 S3 存储桶
- javascript - 如何在点击时从屏幕外制作一个空白方块?
- sql - 在 oracle sql 中处理工作日日期的条件
- qt - 代理模型中不需要的空行
- python - 将元素添加到 3D 数组中第一个数组的第一个数组时,Numpy 数组的尺寸会发生变化
- flutter - 创建后如何访问(MaterialApp的)“主”导航器?
- java - FXMLLoader.getController() 返回 null
- python - 如何在 python 中创建内联 for 循环来对数字列表求和?