Javascript:返回 false 不起作用,即使在我按下取消后代码被执行
我正在尝试用 1 个按钮执行 2 个 javascript。当第二个脚本执行时,即使我单击取消,代码也会被执行。下面是代码。有人能帮帮我吗?
<script type="text/javascript" language="javascript">
var TargetBaseControl = null;
window.onload = function () {
try {
//get target base control.
TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
} catch (err) {
TargetBaseControl = null;
}
}
function TestCheckBox() {
if (TargetBaseControl == null) return false;
//get target child control.
var TargetChildControl = "chkSelect";
//get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 && Inputs[n].checked) return true;
alert('Please select at least one Request to Close!');
return false;
}
function UpdateConfirmation() {
if (confirm("Are you sure, you want to close selected request ?") == true) return true;
else return false;
}
</script>
<asp:Button ID="btnUpdate" runat="server"
OnClick="btnUpdate_Click" Text="Close Request"
OnClientClick="var b = TestCheckBox(); if (b) UpdateConfirmation(); return b"/>