我不明白,但所有显示的都是HTML“结束”,没有任何javascript正在运行。为什么?浏览器是chrome并设置为允许javascript。在地址栏中执行javascript:alert('hello')工作!
<html>
<title>
Javascript test
</title>
<head>
<body>
<script
type="text/javascript">
document.write('Hello!');
var = prompt("What is your name?");
alert("Hello, " var);
</script>
<h1>End</h1>
</head>
</body>
</html>
答案 0 :(得分:1)
这些行中存在语法错误:
//Missing variable name
var = prompt("What is your name?");
alert("Hello, " var);
尝试:
var x = prompt("What is your name?");
alert("Hello, " + x);
答案 1 :(得分:0)
var = prompt("What is your name?");
您尚未声明变量
var name = prompt("What is your name?");
alert("Hello, " + name);
答案 2 :(得分:0)
您忘记声明变量名称:
var res = prompt("What is your name?");
alert("Hello, " res);