当我更改过滤器时,所有值都会更改。我只想更改'block-value' HTML 的值



我尝试为第二个元素'block-value'显示valueToday[1],我尝试为第一个元素'block-value'显示valueToday[0]。但是divs[i].querySelector(class).style.display = ""不起作用我的过滤器调用了每个元素:

let values = document.querySelectorAll('.value-h6');
let valueToday = document.querySelectorAll('.value-today');
let valueMonth = document.querySelectorAll('.value-month');
let valueYear = document.querySelectorAll('.value-year');
let divs = document.querySelectorAll('block-value');
function init() {
// Clear data
for (let i = 0; i < values.length; i++) {
values[i].style.display = "none";
}
for (let i = 0; i < valueToday.length; i++) {
valueToday[i].style.display = 'block';
}
}
// user is coming, the default value is the dailyValue
init();
function today() {
init();
}
function month() {
for (let i = 0; i < values.length; i++) {
values[i].style.display = "none";
}
for (let i = 0; i < valueMonth.length; i++) {
valueMonth[i].style.display = 'block';
}
}
function year() {
for (let i = 0; i < values.length; i++) {
values[i].style.display = "none";
}
for (let i = 0; i < valueYear.length; i++) {
valueYear[i].style.display = 'block';
}
}
<div class="ps-3 block-value" id="0">
<h6 class="value-h6 value-today">23%</h6>
<h6 class="value-h6 value-month">24%</h6>
<h6 class="value-h6 value-year">25%</h6>
</div>
<div class="ps-3 block-value" id="1">
<h6 class="value-h6 value-today">300</h6>
<h6 class="value-h6 value-month">34</h6>
<h6 class="value-h6 value-year">23</h6>
</div>
<li><button class="dropdown-item filter-btn filter-auj" onclick="today()">Aujourd'hui</button></li>
<li><button class="dropdown-item filter-btn filter-mois" onclick="month()">Ce mois</button></li>
<li><button class="dropdown-item filter-btn filter-annee" onclick="year()">Cette année</button></li>

Try display = 'none' (https://www.w3schools.com/jsref/prop_style_display.asp#:~:text=The%20display%20property%20also%20allows,its%20original%20position%20and%20size.)W3schools在这些方面有很好的文档;-)

相关内容

最新更新