簡單的按鈕,應該創建新的<p>
元素,當它被點擊,但它不工作,我不知道爲什麼,因爲我已經將它與其他代碼進行了比較。.append不起作用點擊
var battle = function() {
while(monsterHP > 0){
var playerDam = Math.floor(Math.random() * ((playerAtk - monsterAtk) + 2);
$('#battle').append("<p>You have hit the monster for " + playerDam + " damage. The monster has " + (monsterHP - playerDam) + "HP left</p>");
monsterHP -= playerDam;
if(monsterHP <= 0) {
$('#battle').append("<p>You have defeated the monster</p>");
}
}
}
$('#battleButton').click(function() {
battle();
}
你看過瀏覽器控制檯嗎?有一個語法錯誤。 – Xufox