Code
<!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>
<script type="text/javascript" src="../../Content/jquery-1.2.6.min.js"></script>
<script>
$(function() {
$("#Mail").blur(function() {
chkMail();
});
$("#form1").submit(function() {
return chkMail() == false;
});
$("#Mail").focus();
});
function chkMail() {
var isErr = false;
if (!$("#Mail").val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)) {
$('#MailImg').html("<img src='../../Content/exclamation.gif' />");
$('#MailMsg').html("邮件地址格式不对").attr("style", "color:red;");
isErr = true;
}
else {
$('#MailImg').html("");
$('#MailMsg').html("");
}
return isErr;
}
</script>
<title>
</title></head>
<body>
<div>
<form id="form1" action="/Forgot/Step1" method="post">
<li>请输入邮箱:
<input id="Mail" name="Mail" type="text" value="" /><span id="MailImg"></span><span id="MailMsg"></span>
</li>
<li>
<input type="Submit" name="Next" id="Next" value="下一步" />
</li>
</form>
</div>
</body>
</html>
这里的focus第一次载入好像没有焦点,再刷新一次又有了,为什么哈