为什么没我把window.onload=function{}就可以正常运行,不去就不能运行呢?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<!--<link type="text/css" href="../Mycss/mcss2.css" rel="stylesheet">-->
<style type="text/css">
.init{background: #f5f5f5;font-weight:bold;font-size: 10px;color:#000000;}
#img1{width: 15px;height:15px;display: none;}
#img2{width: 15px;height:15px;display: none;}
.wrong{background: #f5f5f5;font-weight:bold;border:1px #ff0000 solid;color:#000000;}
.right{background: #f5f5f5;font-weight:bold;border:1px #00ff00 solid;color:#000000;}
</style>
<script type="text/javascript">
//window.onload=function() {
function validateEmail() {
var oImg1=document.getElementById("img1");
var oImg2=document.getElementById("img2");
var oIpt=document.getElementById("ipt1");
if(/^\w+@\w+\.\w+$/.test(oIpt.value)){
oIpt.className='right';
oImg2.style.cssText='display:inline-block';
oImg1.style.cssText='display:none';
return true;
} else {
oIpt.className='wrong';
oImg1.style.cssText='display:inline-block';
oImg2.style.cssText='display:none';
return false;
}
}
function validate() {
return validateEmail();
}
//}
</script>
</head>
<body>
<form id="myform" action='show.html' method='post' onsubmit="return validate()">
<div>
请输入常用邮箱地址:
<input type="text" id="ipt1" name="ipt1" class="init" onblur="validateEmail()">
<img id="img1" src="D:/Documents/Pictures/source material image/a.jpg"/>
<img id="img2" src="D:/Documents/Pictures/source material image/c.png"/>
</div>
<br>
<button type="submit">干嘛</button>
</form>
</body>
</html>