我有一个令人困惑的问题。
如下代码,我看不出有什么问题,我已经与我的其他代码进行了比较,它的格式完全相同/非常相似,但是这个由于某种原因没有执行事件。
我也试过在 if 语句中这样做:
if (regExName.test(theForm.txtName.value))
仍然是同样的错误,根本没有任何反应。lbl???根本不显示它是否工作的消息。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 265px;
}
#Text1 {
width: 186px;
}
#Text2 {
width: 186px;
}
#Text3 {
width: 186px;
}
#txtName {
width: 186px;
}
#txtAge {
width: 186px;
}
#txtNumber {
width: 186px;
}
</style>
<script language="javascript" type="text/javascript">
function btnValidate(theForm) {
regExName = new RegExp("[a-zA-Z]");
regExAge = new RegExp("^([1])?[0-9]{2}");
regExNum = new RegExp("[2-9][0-9]{2}\-[0-9]{4}");
if (regExName.test(theForm.txtName))
lblName.innerHTML = "Valid, continue.";
else
lblName.innerHTML = "Invalid Name Entry, please try again.";
if (regExAge.test(theForm.txtAge))
lblAge.innerHTML = "Valid, continue.";
else
lblAge.innerHTML = "Invalid Age Entry, please try again.";
if (regExNum.test(theForm.txtNumber))
lblNumber.innerHTML = "Valid, continue.";
else
lblNumber.innerHTML = "Invalid Phone Number Entry, please try again.";
}
</script>
</head>
<body>
<form action="">
<table class="auto-style1">
<tr>
<td class="auto-style2">Name:
<input id="txtName" type="text" /></td>
<td>
<div id="lblName">
</div>
</td>
</tr>
<tr>
<td class="auto-style2">Age:
<input id="txtAge" type="text" /></td>
<td>
<div id="lblAge">
</div>
</td>
</tr>
<tr>
<td class="auto-style2">Number:
<input id="txtNumber" type="text" /></td>
<td>
<div id="lblNumber">
</div>
</td>
</tr>
</table>
<p>
<input id="Submit1" type="submit" value="Validate" onsubmit="btnValidate(this.form)"/></p>
</form>
</body>
</html>
任何帮助将不胜感激。
更新代码