【发布时间】:2020-08-24 17:19:06
【问题描述】:
确认正常按钮不起作用,它没有调用服务器端方法。
按钮被禁用,但未调用服务器端函数。
如果我从确认方法中删除以下两行,那么它工作正常;
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>
有什么想法吗?
【问题讨论】:
-
没有
.attr()方法。您将 jQuery API 与 DOM API 混淆了。 -
对不起,我输入了错误的代码。我已经更新了我的问题
-
您是否检查过浏览器控制台是否有其他错误? ASP 不会为你创建奇怪的元素 ID 吗?
-
如果您在控制台中输入
document.getElementById('btnSubmit')会发生什么?参考上面的尖尖评论 -
在您的
OnClientClick中出现retuen的拼写错误,请将其更改为return
标签: javascript asp.net webforms