HTML 和 JavaScript 无法正确编译
HTML and javascript not compiling properly
这段代码在几周前似乎工作正常。
然而,现在,分支似乎完全被破坏了(浏览器类型意义不大)。
有人知道为什么它可能不再工作吗?
这是代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Examples of Strings</title>
<script type="text/javascript">
//<![CDATA[
<!-- hide me
// get a name
var monkey = prompt("What's the monkey's name?","The monkey");
// declare some short strings
var demanding = " demands - no - insists upon receiving ";
var requesting = " nicely asks for the benefit of all ";
var tech = " a computer that won't crash, and a homemade browser!";
var peace = " love for everyone and peace on earth.";
// construct some longer strings
var userRequest = "Do you want to hear what "+ monkey + " wants?"
var techy_monkey = monkey + demanding + tech;
var hippy_monkey = monkey + requesting + peace;
// make some fancy strings
var bold_tech = techy_monkey.bold();
var italic_hippy = hippy_monkey.italics();
var shouting_hippy= hippy_monkey.toUpperCase();
var red_bold_tech = bold_tech.fontcolor('red');
// stop hiding me -->
//]]>
</script>
</head>
<body>
<h1>Monkey Babbles</h1>
<script type="text/javascript">
//<![CDATA[
<!-- hide me
var monkey_love = prompt("Do you love the monkey?","Type yes or no");
if (monkey_love == "yes")
{
alert("Welcome! I'm so glad you came! Please, read on!");
var monkey_statement = prompt(userRequest,"Type yes or no");
if (monkey_statement == "yes")
document.writeln(italic_hippy + "<br>");
break;
}
else if (monkey_love == "no")
{
alert("Just giving you the heads up: the monkey hates you too");
var monkey_statement = prompt("Do you want to hear what the monkey wants?","Type yes or no");
if (monkey_statement == "yes")
document.writeln(red_bold_tech + "<br>");
break;
}
else if (monkey_love == "Type yes or no")
{
alert("Do you just randomly click on dialog boxes?");
var monkey_statement = prompt("Do you want to hear what the monkey wants?","Type yes or no");
if (monkey_statement == "yes")
document.writeln(shouting_hippy + "<br>");
else {
document.writeln("The monkey is pained by your general lack of interest")
}
break;
}
else
{
alert("You make no sense to monkey");
var monkey_statement = prompt("Do you want to hear what the monkey wants?","Type yes or no");
if (monkey_statement == "yes")
document.writeln(bold_tech + "<br>");
break;
}
// show me -->
//]]>
</script>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
</body>
</html>
不能
将break
语句放在if
子句中。如果我正确阅读了您的代码,您只需删除它们,一切都应该没问题。
相关文章:
- 如何在Windows中将Javascript文件编译成二进制文件
- Javascript赢得'不能在IE上编译,但可以在Chrome上运行
- ScriptEngineManager能给我它刚刚用Java编译的Javascript函数的名称吗
- 在JavaScript中编译搜索后,获取链接到函数的属性标记的Element
- 无法使用 ant 和闭包编译器编译 javascript,因为 Jquery 的 $ 是未声明的
- 为什么每个人都使用 Node.js 和 NPM 来编译 JavaScript 库
- 使用KJSCompiler编译javascript后的JSCOMPILER_PRESERVE
- Rails没有预编译javascript
- 使用requirejs编译javascript程序以删除require依赖项
- 编写CoffeeScript时,编译Javascript中不必要的return关键字
- 预编译javascript中的验证器函数
- 用Rhino在Java内部编译JavaScript
- 使用Gulp编译javascript并解析依赖项(单独的文件)
- rails 3.1中的EJS gem无法正确编译JavaScript模板
- 如何创建makefile来编译javascript
- 资产管道只编译Javascript文件
- JScript条件编译+JavaScript压缩=预处理器
- PhantomJS不会使用类定义编译JavaScript脚本
- 如何为浏览器编译javascript库?
- 调试闭包编译器编译Javascript