我想用Javascript格式編寫一個簡單的「選擇你自己的冒險」風格的遊戲,主要是因爲它很簡單,但我遇到了問題。我試圖讓JavaScript運行在頁面加載,但它不會開始。我只剩下一個空白頁面。功能標籤似乎不起作用?
下面是代碼:
<!doctype html>
<body>
<title>Dungeons and Dwarves</title>
<script type="text/javascript>
function begin() {
alert("Welcome to Dungeons and Dwarves! A free 'Choose Your Own Adventure' game. In this adventure, you will be faced with many decisions, some of which could potentially lead to your death. If you are willing to put your life on the line, and leap forward into a new world and explore the unexplored, press OK to begin.")
var myAge = prompt("How old are you, adventurer?")
if (myAge < 18)
{
alert("Oh! They start younger and younger every year! You'll be careful out there, wont you?")
}
else
{
alert("I see you have had some experience with adventures! I wish you the best of luck, not that you will need it!")
}
}
</script>
<body onload='javascript:begin()'>
</body>
林不知道我做錯了這裏,但我認爲功能標籤不能正常工作。就像它在Notepad ++中看起來那樣,這可能就是我。任何人都可以給我協助嗎?
我很抱歉如果我格式化了這個錯誤。
你有2個身體標籤。我假設1st是爲了成爲一個html標籤,也需要在文檔結尾處關閉。 – Archer
@Archer - 你的意思是'head'標籤 – johnnycardy
還有一個缺少的報價。 – Robin