0
Doubt
With this code, I can only create and manipulate a "employee", I wanted to be able to add more employees by clicking a button and manipulate their data.
HTML
<!DOCTYPE html>
<html>
<body>
Funcionario: <div id="func"></div>
<button id="alternome">Alterar nome</button>
Salario: R$<div id="salario"></div>
<button id="aumenta">+</button><button id="abaixa">-</button>
</body>
</html>
Javascript
function funcionario(){
//altera div func
var f = document.getElementById("func");
var s2 = f.innerHTML;
f.innerHTML = prompt("Qual o nome do funcionario??");
//pos-alteramento de nome
var a= document.getElementById("alternome");
a.onclick = function alternome(){
f.innerHTML = prompt("Qual o nome atual?");
}
//altera div salario
var n=document.getElementById("salario");
var s1 = n.innerHTML;
n.innerHTML = prompt("Qual o salario?");
//aumenta valor
var m=document.getElementById("aumenta");
m.onclick = function aumenta(){
//gambiarra para aumentar o valor 100X
for(var i=0;i<100;i++){
n.innerHTML++;
}
};
//decrementa valor
var o=document.getElementById("abaixa");
o.onclick = function abaixa(){
//gambiarra para abaixar o valor 100X
for(var i=0;i<100;i++){
if(n.innerHTML==0){
continue;
}
n.innerHTML--;
}
};
}
//tem q colocar essa função pra funcionar os bagui
setTimeout(funcionario, 500);
Hello Mr. We have made suggestions for code. Make sure they help you. If the answer is positive, and mark as solved, or if you liked the answer give an UP to help our reputation.
– Rogerio Soares Ferreira