javascript - why does javascript load before html? i put the body's content before the script but it still does'nt work
问题描述
<!DOCTYPE html>
<html>
<head>
<title>facebook</title>
</head>
<body>
<h1>facebook</h1>
<script type="text/javascript" src="face.js"></script>
</body>
</html>
and here is my js code:
var database = [
{
username: "yotythepro",
password: "1234"
},
{
username: "ravit012",
password: "3314"
}
];
var newsfeed = [
{
username: "Bobby",
timeline: "So tired from all that learning!"
},
{
username: "Sally",
timeline: "Javascript is sooooo cool!"
},
{
username: "Mitch",
timeline: "Javascript is preeetyy cool!"
}
];
var signName = prompt("username?");
var signPass = prompt("password?");
function signIn(name, pass) {
database.forEach(function(user, i){
if (name === database[i].username && pass === database[i].password) {
console.log(newsfeed);
} else if (i === database.length - 1) {
alert("username or password are incorrect!");
}
})
}
signIn(signName,signPass);
this is my code can anyone please tell me why does the h1 not load before the alerts finish even though the script tag is at the end of the body? i am new to javascript so i might have missed something super obvious.
解决方案
推荐阅读
- php - Uncaught ReferenceError: $ is not defined - Laravel 5.5 + Laravel Mix
- react-native - 如何升级 react-native gradle 版本
- javascript - 无法动态创建 div 内容
- proxy - Node.js 中的 Google GAX / gRPC 不适用于 HTTP/S 代理
- javascript - 如何将点分隔字符串中的每个第一个单词大写?
- c - C:如何获取操作系统名称(Ubuntu、Debian、Centos、..)以及如果定义操作系统名称 = ubuntu
- jenkins - 如何在 Jenkins Blue Ocean 阶段为 Github 状态检查指定自定义 url?
- mysql - 插入目标表时跳过mysql中的重复值
- python-2.7 - MySQLdb 导入从命令行工作,但在 PyCharm 中崩溃
- rdf - 空白节点和图形