javascript左手边错误

时间:2013-11-18 23:04:52

标签: javascript

当谈到javascript时,我是一个完整的菜鸟,但是当我尝试“玩”我的头或尾游戏时,我无法得到为什么我会收到参考错误。

document.write("

<button type='button' onclick='kop()'>kop</button></br>
<button type='button' onclick='munt()'>munt</button>
</br></br></br>
<button type='button' onclick='score()'>Score</button>

<p id='ww'></p>
<p id='ll'></p>
</br></br></br>
<p id='wi'></p>
<p id='lo'></p>

");

function kop(){
var keuze="kop";

var out=Math.floor(Math.random()*10+1);

if(out>5){
alert("het is inderdaad "+keuze+"!");
document.getElementById("ww")=document.getElementById("ww")+" ";

}else{
alert("het was munt!!");
document.getElementById("ll")=document.getElementById("ll")+" ";

}
}

function munt(){
var keuze="munt";

var out=Math.floor(Math.random()*10+1);

if(out<=5){
alert("het is inderdaad "+keuze+"!");

document.getElementById("ww")=document.getElementById("ww")+" ";

}else{
alert("het was kop!!");
document.getElementById("ll")=document.getElementById("ll")+" ";

}
};

function score(){

document.getElementById("wi")=document.getElementById("ww").length ;

document.getElementById("lo")=document.getElementById("ll").length;

}

1 个答案:

答案 0 :(得分:0)

将LHS从document.getElementById()替换为

document.getElementById(<id>).innerHTML

例如,更改

document.getElementById("ww")=document.getElementById("ww")+" ";

document.getElementById("ww").innerHTML=document.getElementById("ww")+" ";