当年龄的文本框输错时,不能选中并高亮其中文本,ie下可以,怎么解决?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="content-type" content="text/html;charset=gb2312"/>
<title>简单表单验证</title>
<script language="javascript" type="text/javascript">
function checkForm() {
var myForm = document.form1;
if (myForm.txtAge.value == "" || myForm.txtName.value == "") {
alert("Please complete all the form");
if (myForm.txtName.value == "") {
myForm.txtName.focus();
} else {
myForm.txtAge.focus();
}
} else {
alert("Thanks for completing the form " + myForm.txtName.value);
}
}
function txtAge_onblur() {
var txtAge = document.form1.txtAge;
if ( isNaN(txtAge.value) == true) {
alert("Please enter a valid age");
txtAge.focus();
txtAge.select();
}
}
</script>
</head><body> <form name="form1">
Please enter the following details:
<p>
Name:
<br/>
<input type="text" name="txtName">
<br/>
Age:
<br/>
<input type="text" name="txtAge" size="3" maxlength="3">
<br/>
<input type="button" name="butCheck" value="检查">
</form>
<script language="javascript" type="text/javascript">
document.form1.txtAge.onblur = txtAge_onblur;
document.form1.butCheck.onclick = checkForm;
</script>
</body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="content-type" content="text/html;charset=gb2312"/>
<title>简单表单验证</title>
<script language="javascript" type="text/javascript">
function checkForm() {
var myForm = document.form1;
if (myForm.txtAge.value == "" || myForm.txtName.value == "") {
alert("Please complete all the form");
if (myForm.txtName.value == "") {
myForm.txtName.focus();
} else {
myForm.txtAge.focus();
}
} else {
alert("Thanks for completing the form " + myForm.txtName.value);
}
}
function txtAge_onblur() {
var txtAge = document.form1.txtAge;
if ( isNaN(txtAge.value) == true) {
alert("Please enter a valid age");
txtAge.focus();
txtAge.select();
}
}
</script>
</head><body> <form name="form1">
Please enter the following details:
<p>
Name:
<br/>
<input type="text" name="txtName">
<br/>
Age:
<br/>
<input type="text" name="txtAge" size="3" maxlength="3">
<br/>
<input type="button" name="butCheck" value="检查">
</form>
<script language="javascript" type="text/javascript">
document.form1.txtAge.onblur = txtAge_onblur;
document.form1.butCheck.onclick = checkForm;
</script>
</body></html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货