我有這個腳本,即時通訊使用作爲學習的東西。在這個代碼即時通訊嘗試擁有它,以便每次按鈕被點擊時,它將運行多個代碼。比如每次失去1點耐力,改變3件事中的1件(金錢,耐力或健康),然後更新屏幕上的號碼。不幸的是,我的號碼沒有更新。我之前只用一個函數調用了這個程序,但現在我有多個,它引發了問題。函數內的調用函數
<html>
<head>
<script>
var stam=100;
var cash=0;
var health=100;
var rNumber=Math.random();
function explore(){ //2<- This function gets called and runs two functions
if(stam>1){
redStam();
refresh();
//<-- will add a function to use a random number later to decide whether health, money or stamina gets changed.
};
else{alert("You have no stamina")}}
function refresh(){ //3<-This function gets called, which refreshes the current variables
document.getElementById('number').innerHTML=stam;
};
function redStam(){ //3<This function also gets called.
stam--;
};
</script>
<button onclick="explore()">Explore</button> 1<- button gets clicked
</head>
<body>
<p id='number'>100</P>
</body>
</html>
什麼問題?另外請注意,函數聲明require(),例如,函數redStam(){} – cernunnos 2013-03-25 15:21:28
我開始編輯這個格式,但有太多的語法錯誤,我不確定我會做得更好。 OP,請正確縮進您的代碼,並確保您發佈至少語法上有效的代碼......無論它是否有效。 – BLSully 2013-03-25 15:24:27
只是將問題添加到帖子中..我也剛剛更改了我的代碼以在我的函數中使用(),但代碼仍然無法正常工作 – 2013-03-25 15:24:45