我正在尝试学习Javascript,并试图在HTML脚本中包含提示和警报。
请问有人可以注意下面的代码有什么问题吗?
<html>
<head>
<title>test</title>
<script src="stalker.js"></script>
</head>
<body>
<h1>test</h1>
</body>
</html>
这是JavaScript代码:
prompt(“what is your first name?”);
var fname = prompt(“what is your first name?”);
prompt(“what is your last name?”)
var lname = prompt(“what is your last name?”);
prompt(“what is your age?”);
var age = prompt(“what is your age?”)
有人可以告诉我为什么当我在浏览器中运行它时提示不运行吗?
答案 0 :(得分:2)
我将您的Java脚本代码粘贴到了我的文件中并进行了检查。看起来您的代码中有双引号而不是双引号。
下面的代码对我有用。
var fname = prompt("what is your first name?");
prompt("what is your last name?")
var lname = prompt("what is your last name?");
prompt("what is your age?");
var age = prompt("what is your age?")
当您认为自己的js代码不起作用时,也可以单击F12或打开控制台以查看错误。
答案 1 :(得分:0)
尝试:使用“您的名字是什么?”
var fname = prompt("what is your first name?");
prompt("what is your last name?")
var lname = prompt("what is your last name?");
prompt("what is your age?");
var age = prompt("what is your age?")
答案 2 :(得分:0)
为您确认: HTML标记错误,“应为"
。
var fname = prompt("what is your first name?");
console.log("name: "+ fname)
<html>
<head>
<title>test</title>
</head>
<body>
<h1>test</h1>
</body>
</html>