//感谢杨老师
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>form</title>
</head>
<body>
<form action="">
<input type="text" id='username'>
<input type="password" id='password'>
<input type="submit">
</form>
<script type="text/javascript">
document.querySelector('#username').οnchange=function(){
alert(this.value)
}
// document.querySelector('#password').οnfοcus=function(){
// alert(this.tagName)
// }
document.querySelector('#username').οnblur=function(){
alert(this.value)
}
document.querySelector('form').οnsubmit=function(){
if(!document.querySelector('#username').value||!document.querySelector('#password').value){
alert('请将用户名及密码填写完整');
return false;
}
}
</script>
</body>
</html>