2011-04-06 75 views
0

這段代碼似乎在幾個星期前正常工作。HTML和javascript編譯不正確

然而,現在分支似乎完全破碎(瀏覽器類型意義不大)。

有沒有人知道爲什麼它可能不再工作?

下面是代碼:

<!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> 
+5

HTML和JavaScript從不編譯。 – 2011-04-06 15:32:12

+4

檢查您的JavaScript控制檯(在Firefox中shift-ctrl-J)並查找javascript錯誤。 – 2011-04-06 15:33:59

回答

1

你不能把break語句if條款。如果我正確地閱讀了你的代碼,你可以簡單地刪除它們,所有的都應該沒問題。

+1

或者「開關」,如果別的術語到開關語句;-) – Alex 2011-04-06 15:59:07