-2

我一直在尝试找到一种可以理解的创建 JS 按钮的方法,但我无法理解父节点孩子吃东西之类的东西。我觉得自己离完善我的小游戏很近了,但还不能完全做到。

var health=100;
var ehealth=100;
var atk;
var eatk;

function attack(x){
  x=Math.floor(Math.random()*11);
  atk=x;
  ehealth=ehealth-atk
  document.write('Enemy Health:' + '   ' + ehealth + '   ')
}

function eattack(x){
  x=Math.floor(Math.random()*11);
  eatk=x;
  health=health-eatk
  document.write('Health:' + '&nbsp; &nbsp;' + health + '<br/>\n')
}

function dead(){
  if(health<=0&&ehealth<=0){
    document.write('A Draw');
  }else{
    if(health<=0){
      document.write('You Lose');
    }else{
      if(ehealth<=0){
        document.write('You Win');
      }
    }
  }
}

function battleRound() {
  attack(0);
  eattack(0);
  dead();

  if( health>=0&&ehealth>=0 ) {
    setTimeout( battleRound, 400 );
  }
}
</script>
<button onclick='battleRound()'>Start</button>
<button onclick="document.location.reload(true)">Reset</button>
</body>

我希望在战斗完成后出现重置按钮,但整个互联网似乎都在尖叫子节点和父节点:(我今天问的第四个问题,为我的新手-ish-nes 感到抱歉

4

1 回答 1

1

您可以在重置按钮上添加一种显示样式:无,然后在战斗完成后通过使用显示它。

element.removeAttribute("style")
于 2013-10-22T12:53:16.390 回答