微件: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 | const characterName = '{{{characterName}}}'; // 从模板参数中获取角色名 | ||
// 构造数据页面URL | |||
const dataUrl = `/wiki/Data:${characterName}/属性.json`; | |||
const | |||
levelSlider. | fetch(dataUrl) | ||
.then(response => response.json()) | |||
.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'); | |||
levelSlider.addEventListener('input', function() { | |||
const level = levelSlider.value; | |||
currentLevel.textContent = level; | |||
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> |