的Javascript:返回false不工作,即使我按取消代碼被執行的Javascript:返回false不工作:即使我按取消代碼被執行
我試圖執行2倍的JavaScript與1個按鈕。當第二個腳本執行時,即使我單擊取消,代碼也會執行。以下是代碼。有人能幫幫我嗎?
<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"/>
您從事件處理程序返回'B',不'UpdateConfirmation的返回值'。 – 2013-02-21 06:29:47
@Aditya我在你的問題答案中加了一些解釋。 – nnnn 2013-02-21 07:18:21