Enviado em 14/07/2015 - 18:29h
Estou aqui para pergunta, como faço para programar um botão para deletar somente UM número dessa minha calculadora
Já tenho um botão para limpar tudo, mas quero um que delete somente UM digito do VSOR
A Nomenclatura dos objetos HTML e das funcões JavaScript são somente ilustrativa
Código HTML
Código JavaScript
O Código tá meio NOOB mas acho que da pro gasto
:D
Já tenho um botão para limpar tudo, mas quero um que delete somente UM digito do VSOR
A Nomenclatura dos objetos HTML e das funcões JavaScript são somente ilustrativa
Código HTML
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<meta charset="utf-8" />
<!-- Estilo -->
<style>
* {
margin: 0;
padding: 0;
}
body {
width: 100%;
height: auto;
background: #CCCCCC;
font-family: Arial ,Tahoma ,Helvetica ,sans-serif;
font-size: 20px;
text-align: center;
color: #333333;
margin: 0 auto;
}
.btnc {
width: 30px;
height: 30px;
background: #666;
color: #000;
font-family: Tahoma,Arial,sans-serif;
font-size: 10px;
}
</style>
<!-- Fim Estilo -->
<!--Chamando arquivo JS-->
<script src="javascript.js"></script>
</head>
<body>
<h1>Calculador </h1>
<h1 style="color: #FF0000;">RED</h1>
<h1>Build 001</h1>
<h2 id="hMensagem"
style="font-size: 13px; border:1px solid #333;"
></h2>
<input type="text" id="vsor" size="20" /><br /><br />
<input type="button" name="btn" class="btnc" value="1" onclick="writeN(1);" />
<input type="button" name="btn" class="btnc" value="2" onclick="writeN(2);" />
<input type="button" name="btn" class="btnc" value="3" onclick="writeN(3);"/>
<input type="button" name="btn" class="btnc" value="+" onclick="writeP('+');" /><br /><br />
<input type="button" name="btn" class="btnc" value="4" onclick="writeN(4);" />
<input type="button" name="btn" class="btnc" value="5" onclick="writeN(5);" />
<input type="button" name="btn" class="btnc" value="6" onclick="writeN(6);" />
<input type="button" name="btn" class="btnc"value="-" onclick="writeP('-');" /><br /><br />
<input type="button" name="btn" class="btnc" value="7" onclick="writeN(7);" />
<input type="button" name="btn" class="btnc" value="8" onclick="writeN(8);" />
<input type="button" name="btn" class="btnc" value="9" onclick="writeN(9);" />
<input type="button" name="btn" class="btnc"value="*" onclick="writeP('*');" /><br /><br />
<input type="button" name="btn" class="btnc" value="C" onclick="clearV();"/>
<input type="button" name="btn" class="btnc"value="0" onclick="writeN(0);"/>
<input type="button" name="btn" class="btnc" value="=" onclick="mOperation();" />
<input type="button" name="btn" class="btnc"value="/" onclick="writeP('/');" /><br /><br />
</body>
</html>
Código JavaScript
//--------------------------------------------------------------------
function mfSegundos(num) { //Trasforma Milesegundo em Segundos
var seg = num * 1000;
return seg;
}
//---------------------------------------------------------------------
function clearV() { //Limpar o Visor da Calculadora
/*
Projeto: Calculadora;
Programado por: Retynck;
Data: 14/07/2015;
*/
//Animação :D
var segundos = mfSegundos(2);
document.getElementById('hMensagem').innerHTML = 'Limpo';
setTimeout("document.getElementById('hMensagem').innerHTML = '' ", segundos );
//Limpa de verdade
document.getElementById('vsor').value = '';
}
function writeN(num) { //Ler Numeros
document.getElementById('vsor').value = document.getElementById('vsor').value + num;
}
function writeP(num) { //Ler Operadores
document.getElementById('vsor').value = document.getElementById('vsor').value + num;
}
function mOperation() {
var result = document.getElementById('vsor').value;
document.getElementById('vsor').value = '';
document.getElementById('vsor').value = eval(result);
}
O Código tá meio NOOB mas acho que da pro gasto
:D