微件:PlantFilter:修订间差异
来自植物大战僵尸杂交版Wiki
更多操作
创建页面,内容为“<includeonly> <style> .pvzhe-filter-box { margin: 10px 0; padding: 10px; background: #f5f5f5; border: 1px solid #ccc; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; } .pvzhe-filter-box input, .pvzhe-filter-box select { padding: 4px; } .pvzhe-card.hidden-card { display: none; } </style> <div class="pvzhe-filter-box"> <input type="text" id="pf-name" placeholder="名称搜索..."> <label>阳光 ≤ <input type="number" id=…” |
无编辑摘要 |
||
| 第26行: | 第26行: | ||
<option value="">全部类型</option> | <option value="">全部类型</option> | ||
<option value="生产">生产</option> | <option value="生产">生产</option> | ||
<option value=" | <option value="远程">远程</option> | ||
<option value="防御">防御</option> | <option value="防御">防御</option> | ||
<option value=" | <option value="爆炸">爆炸</option> | ||
</select> | </select> | ||
<button id="pf-reset">重置</button> | <button id="pf-reset">重置</button> | ||
| 第38行: | 第35行: | ||
<script> | <script> | ||
(function() { | (function() { | ||
// 等页面加载完再执行 | |||
document.addEventListener('DOMContentLoaded', function() { | |||
var | var nameInput = document.getElementById('pf-name'); | ||
var | var sunMaxInput = document.getElementById('pf-sun-max'); | ||
var | var cdMaxInput = document.getElementById('pf-cd-max'); | ||
var | var typeSelect = document.getElementById('pf-type'); | ||
var resetBtn = document.getElementById('pf-reset'); | |||
var cards = document.querySelectorAll('.pvzhe-card'); | |||
function filterCards() { | |||
var | var name = nameInput.value.toLowerCase(); | ||
var sunMax = parseFloat(sunMaxInput.value) || Infinity; | |||
var | var cdMax = parseFloat(cdMaxInput.value) || Infinity; | ||
var | var type = typeSelect.value; | ||
var | |||
var | cards.forEach(function(card) { | ||
var n = (card.getAttribute('data-name') || '').toLowerCase(); | |||
var sun = parseFloat(card.getAttribute('data-sun')) || 0; | |||
var cd = parseFloat(card.getAttribute('data-cooldown')) || 0; | |||
var t = card.getAttribute('data-type') || ''; | |||
var show = true; | |||
if (name && n.indexOf(name) === -1) show = false; | |||
if (sun > sunMax) show = false; | |||
if (cd > cdMax) show = false; | |||
if (type) { | |||
var cardTypes = t.split(',').map(function(s) { return s.trim(); }); | |||
if (cardTypes.indexOf(type) === -1) show = false; | |||
} | |||
card.classList.toggle('hidden-card', !show); | |||
}); | |||
} | |||
// 绑定事件 | |||
nameInput.addEventListener('input', filterCards); | |||
sunMaxInput.addEventListener('input', filterCards); | |||
cdMaxInput.addEventListener('input', filterCards); | |||
typeSelect.addEventListener('change', filterCards); | |||
resetBtn.addEventListener('click', function() { | |||
nameInput.value = ''; | |||
sunMaxInput.value = ''; | |||
cdMaxInput.value = ''; | |||
typeSelect.value = ''; | |||
filterCards(); | |||
}); | }); | ||
}); | }); | ||
})(); | })(); | ||
</script> | </script> | ||
</includeonly> | </includeonly> | ||