我想调用两个函数,如果第一个返回 true,则继续执行第二个,如果返回 false,则显示错误。这将在一次 onclientclick 中定义。
如果单击按钮后只调用一个函数,则该函数有效。
但是,如果我这样组合并编写它: TestCheckBox() 和 TestCheckBox2() 是相同的功能,我只需要它来验证两个网格视图
<script type="text/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 = "chkRow";
//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('Select at least one checkbox!');
return false;
}
</script>
问题是当 TestCheckBox() 返回 true 时,TestCheckBox2() 不起作用,在这种情况下它不会验证复选框。
我怎样才能让它完美地工作?