Correction status:qualified
Teacher's comments:不错
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>JavaScript基础知识</title> </head> <body> <h3>JS变量,语句,表达式</h3> 输入名字:<input type="text" name="name" id="input-a" onblur="log(this.value)"> <p id="js-p-a" style="color:red;font-weight:500;"></p> </body> </html> <script> //定义一个变量 var username = "xiaohu"; //定义一个命名函数 function reg() { alert('hao'); } //定义一个函数 function log($name) { //一个简单if语句 if ($name == username) { alert("登录成功"); document.getElementById("js-p-a").innerHTML = "欢迎你回来:" + $name; } else { alert("账户或密码错误"); document.getElementById("input-a").value = ''; document.getElementById("js-p-a").innerHTML = "账户或密码错误,请重新输入"; } } //一个匿名函数 window.onload = function() { alert("别乱动"); }; //调用一个函数 window.onload = reg(); </script>
点击 "运行实例" 按钮查看在线实例