微件:CharacterAttributes:修订间差异

(创建页面,内容为“<includeonly> <div> <label for="levelSlider">角色等级: <span id="currentLevel">1</span></label> <input type="range" id="levelSlider" min="1" max="100" value="1"> </div> <div id="attributes"> <p>生命值: <span id="health">100</span></p> <p>攻击力: <span id="attack">10</span></p> <p>防御力: <span id="defense">5</span></p> </div> <script> document.addEventListener('DOMContentLoaded', function() { const data = { "levels": { "1": {…”)
 
无编辑摘要
标签已被回退
第12行: 第12行:
<script>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function() {
   const data = {
   const characterName = '{{{characterName}}}'; // 从模板参数中获取角色名
    "levels": {
      "1": {"health": 100, "attack": 10, "defense": 5},
      "2": {"health": 120, "attack": 12, "defense": 6},
      "3": {"health": 140, "attack": 14, "defense": 7},
      "100": {"health": 1000, "attack": 100, "defense": 50}
    }
  };


   const levelSlider = document.getElementById('levelSlider');
   // 构造数据页面URL
  const currentLevel = document.getElementById('currentLevel');
   const dataUrl = `/wiki/Data:${characterName}/属性.json`;
  const health = document.getElementById('health');
  const attack = document.getElementById('attack');
   const defense = document.getElementById('defense');


   levelSlider.addEventListener('input', function() {
   fetch(dataUrl)
    const level = levelSlider.value;
    .then(response => response.json())
    currentLevel.textContent = level;
    .then(data => {
      const levelSlider = document.getElementById('levelSlider');
      const currentLevel = document.getElementById('currentLevel');
      const health = document.getElementById('health');
      const attack = document.getElementById('attack');
      const defense = document.getElementById('defense');


    const attributes = data.levels[level];
      levelSlider.addEventListener('input', function() {
    if (attributes) {
        const level = levelSlider.value;
      health.textContent = attributes.health;
        currentLevel.textContent = level;
      attack.textContent = attributes.attack;
 
      defense.textContent = attributes.defense;
        const attributes = data.levels[level];
     }
        if (attributes) {
  });
          health.textContent = attributes.health;
          attack.textContent = attributes.attack;
          defense.textContent = attributes.defense;
        }
      });
     })
    .catch(error => console.error('Error loading data:', error));
});
});
</script>
</script>
</includeonly>
</includeonly>

2024年6月26日 (三) 20:46的版本