大家好,这是第一次在这里发帖提问。我通常在这里找到问题的答案,但这次不能。我有一个非常简单的待办事项列表Web应用程序,只涉及一些简单的HTML(这是说明)和脚本。每当我在chrome中打开此页面时脚本都会执行,但在我退出脚本之后才会加载html。我尝试过实现内联脚本,aysnc和defer但这些似乎没有帮助。如果我用Mozilla加载页面,那么应用程序运行正常。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>To Do List</title>
</head>
<body>
<h1>To Do List!</h1>
<br>
<ul>
<li><i>list</i>- check your todo list</li>
<li><i>add</i>- add an item onto your todo list</li>
<li><i>remove</i>- deleve an item off of your todo list</li>
<li><i>quit</i>- exit the app</li>
</ul>
<script src= "script.js" > </script>
</body>
</html>
script.js
var todolist=["get a dog"];
alert("hello");
var input= prompt("What would you like to do?");
while (input !== "quit") {
if (input=== "list") {
console.log("*******");
todolist.forEach( function(x,i) {
console.log((i+1) + ": " + x)
})
console.log("*******");
}
else if (input === "add") {
var addition= prompt("What item would you like to add to your todo list?")
todolist.push(addition);
}
else if (input === "remove") {
var i = prompt("Enter the number of the list item to be removed");
todolist.splice(i-1, 1);
}
input= prompt("What would you like to do?")
}
console.log("You have exited the app");