JavaScript window对象onload事件的作用
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<script type="text/javascript">
window.οnlοad=function(){
if(document.login.username.value==""){
document.login.username.focus();
}
else{
document.login.password.focus();
}
};
</script>
作用:进入登录页面,加载并同时光标跳到username输入框
<form name="login">
username:<input type="text" name="username">
password:<input type="password" name="password">
<input type="button" name="submit" value="Submit">
</form>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<script type="text/javascript">
window.οnlοad=function(){
if(document.login.username.value==""){
document.login.username.focus();
}
else{
document.login.password.focus();
}
};
</script>
作用:进入登录页面,加载并同时光标跳到username输入框
<form name="login">
username:<input type="text" name="username">
password:<input type="password" name="password">
<input type="button" name="submit" value="Submit">
</form>
</body>
</html>