0
The idea is to take a sequence of values arranged in li’s that share the same class, convert to integer, add to then perform a conditional test.
I’m using document.getElementsByClassName(nomedaclasse)
(have already said that there is newer instruction to use). Apparently it is not a vector that is returned, because appears Htmlcollection, already tried document.getElementsByClassName(nomedaclasse).value
, but returns Undefined.
Follow down what I’ve been trying:
@font-face{
font-family: 'FonteSite';
src: url("../_fonts/product-sans/product-sans-regular.ttf ");
}
body {
font-family: FonteSite, sans-serif;
margin: 0px;
padding: 0px;
}
.header {
margin: 0 auto;
margin-top: 20px;
width: 40%;
height: 180px;
background-color: #ccc;
position: relative;
}
/*inputs*/
.text {
margin-top: 10px;
}
.situacao {
position: absolute;
width: 100px;
height: 20px;
margin-right: 5px;
border: 1px solid tomato;
background-color: white;
border-radius: 5px;
}
.km_trocadeoleo {
right: 5px;
top: 10px;
}
.km_alinhamento {
right: 5px;
top: 40px;
}
.result_revisao {
right: 5px;
top: 70px;
}
.container {
margin: 0 auto;
width: 40%;
height: 600px;
margin-top: 30px;
display: flex;
justify-content: space-between;
}
.data {
width: 40%;
height: 60%;
padding-left: 5px;
background-color: #ccc;
max-width: 100px;
}
.servico {
width: 40%;
height: 60%;
padding-left: 5px;
background-color: #ccc;
max-width: 200px;
}
.km_final {
width: 40%;
height: 60%;
padding-left: 5px;
background-color: #ccc;
max-width: 150px;
}
li {
list-style: none;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="_css/style.css">
<title>Controle de revisão de veículo</title>
</head>
<body>
<div class="header">
<label for="km_tdo">KM troca de óleo:</label><input class="text" type="text" name="km_tdo" id="km_tdo" autofocus data-rule-required="true"/><button type="button" onclick="estadoAtual()">Ok</button><div class="situacao km_trocadeoleo" id="km_trocadeoleo"></div><br>
<label for="km_alin">KM alinhamento:</label><input class="text" type="text" name="km_alin" id="km_alin" data-rule-required="true"/><button type="button">Ok</button><div class="situacao km_alinhamento"></div><br>
<label for="revisao">Revisão:</label><input class="text" type="text" name="revisao" id="revisao" data-rule-required="true"/><button type="button">Ok</button><div class="situacao result_revisao"></div>
</div>
<div class="container">
<div class="data">
<span style="font-weight: 500; padding-left: 25px">Data</span><br>
01/01/2019
01/01/2019
01/15/2019
01/23/2019
01/30/2019
02/27/2019
03/12/2019
03/28/2019
04/15/2019
04/29/2019
05/21/2019
</div>
<div class="servico">
<span style="font-weight: 500; margin-left: 50px">Serviço</span><br>
TROCA DE OLEO
ALINHAMENTO<br>
REVISÃO<br>
REVISÃO<br>
TROCA DE OLEO <br>
TROCA DE OLEO <br>
TROCA DE OLEO <br>
ALINHAMENTO <br>
ALINHAMENTO <br>
REVISÃO <br>
TROCA DE OLEO
ALINHAMENTO
</div>
<div class="km_final">
<span style="font-weight: 500; margin-left: 25px;">KM Final</span><br>
<ul id="teste">
<li class="km_tdo_realizada">10</li>
<li>7</li>
<li>20</li>
<li>15</li>
<li class="km_tdo_realizada">20</li>
<li class="km_tdo_realizada">20</li>
<li class="km_tdo_realizada">10</li>
<li>15</li>
<li>11</li>
<li>20</li>
<li class="km_tdo_realizada">30</li>
<li>10</li>
</ul>
</div>
</div>
<script>
function estadoAtual(){
var valorEntradaKM = document.getElementById("km_tdo").value;
var km_acumulada_tdo = document.getElementsByClassName('km_tdo_realizada');
/*
if(valorEntradaKM >= 0 && valorEntradaKM <= 5){
document.getElementById("km_trocadeoleo").style.backgroundColor="green";
}*/
}
</script>
</body>
</html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">