为什么我的脚本不能在这个html文档中工作?

时间:2015-10-16 21:27:23

标签: javascript html

我是编程新手,我自学HTML和Javascript以及python。 我有点学习这些语言,我觉得我可以使用javascript在html中处理我正在做的事情之一。 我遇到了一个问题,无论出于何种原因,我的代码根本无法正常工作。 我仔细检查了一切,我确信它们都在正确的位置,所有的角色都是正确的。 到目前为止,这是我的代码。我还处于早期发展阶段,我知道这还没有完成。

<!doctype html>
<html>
<head>
<title>Python game</title>
</head>
<body>

<p>Enter your choice by clicking on the buttons below the paragraph<p>

<p id="newText">kjgkhg</p>
<button type="onClick" id="ChooseFirst">First choice</button>
<button type="onclick" id="chooseSecond">Second choice</button>
<button type="onclick" id="choosethird">Third choice</button>

<script>
document.getElementById("newText").innerHTML = "why doesn't this work?";

funciton darkRoom() {
    vars x=document.getElementById("newText").innerHTML ;
    document.getElementById("newText").innerHTML = "You wake up in a dark room with no \
    idea how you go there. You can make out the outline of three doors\
    labeled '1', '2', and '3' directly in front of you. There is no door behind you.\
    Which door do you enter?";
}

function lions() {
}

function tiger() {
}

functoin bear() {
}

function brickRoad() {
}

function quickSand() {
}

function sizePuzzle() {
}

function riddlesOnWall() {
}

function wolfSheepCabbage() {
}

function duckHunt() {
}

function hangman() {
}

function goldRoom() {
}

function ocean {
}

function winScreen () {
}

function youDie() {
}

</script>
</body>

</html>

1 个答案:

答案 0 :(得分:3)

其中有很多拼写错误,正如Chris L已经指出的那样,尽管Juhana是正确的但是控制台中打印的错误很难为初学者解读(尽管你要学习他们,特别是初学者!)。

以下是一些可以使用

播放的精简模板
<!doctype html>
<html>
<head>
<title>Python game</title>
<script>
function darkRoom() {
    var x=document.getElementById("newText").innerHTML ;
    // You cannot escape the end-of-lines you have to concatenate individual strings
    document.getElementById("newText").innerHTML = "You wake up in a dark room with no " + 
    "idea how you go there. You can make out the outline of three doors" +
    "labeled '1', '2', and '3' directly in front of you. There is no door behind you." +
    "Which door do you enter?";
}
// instead of alert() call another function reacting to the users input
function firstChoosen()  {alert("first choosen");}
function secondChoosen() {alert("second choosen");}
function thirdChoosen()  {alert("third choosen");}
</script>
</head>
<body onload="darkRoom()">
<p>Enter your choice by clicking on the buttons below the paragraph<p>
<p id="newText"> </p>
<!-- there are better methods but it's ok for now -->
<button onclick="firstChoosen()" id="ChooseFirst">First choice</button>
<button onclick="secondChoosen()" id="chooseSecond">Second choice</button>
<button onclick="thirdChoosen()" id="choosethird">Third choice</button>
</body>
</html>