HTML 和 JavaScript 无法正确编译

HTML and javascript not compiling properly

本文关键字:编译 JavaScript HTML      更新时间:2023-09-26

这段代码在几周前似乎工作正常。

然而,现在,分支似乎完全被破坏了(浏览器类型意义不大)。

有人知道为什么它可能不再工作吗?

这是代码:

<!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子句中。如果我正确阅读了您的代码,您只需删除它们,一切都应该没问题。