JS中定义了方法,但是在OnClientClick中说我没有定义此方法
JS中代码
function check() {
if (form1.DropProjectLevel.value == "") {
alert("『项目级别』不能为空,请选择。");
form1.DropProjectLevel.focus();
return false;
}
if (form1.DropSubject.value == "") {
alert("『学科』内容不能为空,请重新输入。");
form1.DropSubject.focus();
return false;
}
if (!checkString(form1.TxtProjectName, '项目名称', 90, 1)) {
return false;
}
// if(!checkString(form1.TxtPostCode,'邮政编码',6,1)) return false;
// {
if (!checkInteger1(form1.TxtPostCode, '邮政编码', 6, 1)) {
return false;
}
}
按钮代码
<asp:Button ID="BtnSubmit" Text="确定" runat="server" OnClick="BtnSubmit_Click" OnClientClick=" return check();" />
点击的时候报错“Microsoft JScript 运行时错误: “check”未定义”
------解决方案--------------------
HTML code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function check()
{
if(document.getElementById("TextBox1").value=="aa")
{
return true;
}else
{
alert("失败");
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return check()"
OnClick="Button1_Click" />
</div>
</form>
</body>
</html>