Problème Calculatrice en JAVASCRIPt
Fermé
providence
Messages postés
98
Date d'inscription
dimanche 22 janvier 2006
Statut
Membre
Dernière intervention
18 novembre 2015
-
30 juil. 2008 à 00:40
internetasso Messages postés 1054 Date d'inscription jeudi 25 octobre 2007 Statut Membre Dernière intervention 30 juin 2013 - 30 juil. 2008 à 11:14
internetasso Messages postés 1054 Date d'inscription jeudi 25 octobre 2007 Statut Membre Dernière intervention 30 juin 2013 - 30 juil. 2008 à 11:14
A voir également:
- Problème Calculatrice en JAVASCRIPt
- Telecharger javascript - Télécharger - Langages
- Calculatrice gratuit - Télécharger - Calcul & Conversion
- Application calculatrice - Télécharger - Calcul & Conversion
- Ma-calculatrice - Télécharger - Calcul & Conversion
- Calculatrice windows 7 - Télécharger - Calcul & Conversion
1 réponse
internetasso
Messages postés
1054
Date d'inscription
jeudi 25 octobre 2007
Statut
Membre
Dernière intervention
30 juin 2013
177
Modifié par crapoulou le 27/09/2010 à 21:24
Modifié par crapoulou le 27/09/2010 à 21:24
tiens aller une petite calculette vite fait bien fait...
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Calculette">
<title>Votre calculette</title>
</head>
<body>
<center>
<p>
<form name="Keypad" action="(Référence vide!)">
<table>
<tr>
<td>
<table border="2" width="50" height="60" cellpadding="1" cellspacing="5">
<tr>
<td colspan="3"><input name="ReadOut" size="24" value="0" width="100%" type="text"></td>
<td </td> <></td>
<td><input name="btnClear" type="button" value=" C " onclick="Clear()"></td>
<td><input name="btnClearEntry" type="button" value=" CE " onclick="ClearEntry()"></td>
</tr>
<tr>
<td><input name="btnSeven" type="button" value=" 7 " onclick="NumPressed(7)"></td>
<td><input name="btnEight" type="button" value=" 8 " onclick="NumPressed(8)"></td>
<td><input name="btnNine" type="button" value=" 9 " onclick="NumPressed(9)"></td>
<td> </td>
<td><input name="btnNeg" type="button" value=" +/- " onclick="Neg()"></td>
<td><input name="btnPercent" type="button" value=" % " onclick="Percent()"></td>
</tr>
<tr>
<td><input name="btnFour" type="button" value=" 4 " onclick="NumPressed(4)"></td>
<td><input name="btnFive" type="button" value=" 5 " onclick="NumPressed(5)"></td>
<td><input name="btnSix" type="button" value=" 6 " onclick="NumPressed(6)"></td>
<td> </td>
<td><input name="btnPlus" type="button" value=" + " onclick="Operation('+')"></td>
<td><input name="btnMinus" type="button" value=" - " onclick="Operation('-')"></td>
</tr>
<tr>
<td><input name="btnOne" type="button" value=" 1 " onclick="NumPressed(1)"></td>
<td><input name="btnTwo" type="button" value=" 2 " onclick="NumPressed(2)"></td>
<td><input name="btnThree" type="button" value=" 3 " onclick="NumPressed(3)"></td>
<td> </td>
<td><input name="btnMultiply" type="button" value=" * " onclick="Operation('*')"></td>
<td><input name="btnDivide" type="button" value=" / " onclick="Operation('/')"></td>
</tr>
<tr>
<td><input name="btnZero" type="button" value=" 0 " onclick="NumPressed(0)"></td>
<td><input name="btnDecimal" type="button" value=" . " onclick="Decimal()"></td>
<td colspan="3"> </td>
<td><input name="btnEquals" type="button" value=" = " onclick="Operation('=')"></td>
</tr>
</table>
</td>
</td></tr>
</table>
</form>
<font face="Verdana,Arial,Helvetica" size="2">
<script language="JavaScript"><!--
var FKeyPad = document.Keypad;
var Accum = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else {
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op) {
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accum += parseFloat(Readout);
else if ( '-' == PendingOp )
Accum -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accum /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accum *= parseFloat(Readout);
else
Accum = parseFloat(Readout);
FKeyPad.ReadOut.value = Accum;
PendingOp = Op;
}
}
function Decimal () {
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear () {
Accum = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent () {
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accum);
}
// -->
</script>
</font></p>
<p></center>
</body>
</html>
C'est basique mais ca fonctionne, tu peux changer tout bien entendu mais le fonctionnement sera le même...
La création d'un site commence par la réflexion de son devenir...
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Calculette">
<title>Votre calculette</title>
</head>
<body>
<center>
<p>
<form name="Keypad" action="(Référence vide!)">
<table>
<tr>
<td>
<table border="2" width="50" height="60" cellpadding="1" cellspacing="5">
<tr>
<td colspan="3"><input name="ReadOut" size="24" value="0" width="100%" type="text"></td>
<td </td> <></td>
<td><input name="btnClear" type="button" value=" C " onclick="Clear()"></td>
<td><input name="btnClearEntry" type="button" value=" CE " onclick="ClearEntry()"></td>
</tr>
<tr>
<td><input name="btnSeven" type="button" value=" 7 " onclick="NumPressed(7)"></td>
<td><input name="btnEight" type="button" value=" 8 " onclick="NumPressed(8)"></td>
<td><input name="btnNine" type="button" value=" 9 " onclick="NumPressed(9)"></td>
<td> </td>
<td><input name="btnNeg" type="button" value=" +/- " onclick="Neg()"></td>
<td><input name="btnPercent" type="button" value=" % " onclick="Percent()"></td>
</tr>
<tr>
<td><input name="btnFour" type="button" value=" 4 " onclick="NumPressed(4)"></td>
<td><input name="btnFive" type="button" value=" 5 " onclick="NumPressed(5)"></td>
<td><input name="btnSix" type="button" value=" 6 " onclick="NumPressed(6)"></td>
<td> </td>
<td><input name="btnPlus" type="button" value=" + " onclick="Operation('+')"></td>
<td><input name="btnMinus" type="button" value=" - " onclick="Operation('-')"></td>
</tr>
<tr>
<td><input name="btnOne" type="button" value=" 1 " onclick="NumPressed(1)"></td>
<td><input name="btnTwo" type="button" value=" 2 " onclick="NumPressed(2)"></td>
<td><input name="btnThree" type="button" value=" 3 " onclick="NumPressed(3)"></td>
<td> </td>
<td><input name="btnMultiply" type="button" value=" * " onclick="Operation('*')"></td>
<td><input name="btnDivide" type="button" value=" / " onclick="Operation('/')"></td>
</tr>
<tr>
<td><input name="btnZero" type="button" value=" 0 " onclick="NumPressed(0)"></td>
<td><input name="btnDecimal" type="button" value=" . " onclick="Decimal()"></td>
<td colspan="3"> </td>
<td><input name="btnEquals" type="button" value=" = " onclick="Operation('=')"></td>
</tr>
</table>
</td>
</td></tr>
</table>
</form>
<font face="Verdana,Arial,Helvetica" size="2">
<script language="JavaScript"><!--
var FKeyPad = document.Keypad;
var Accum = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else {
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op) {
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accum += parseFloat(Readout);
else if ( '-' == PendingOp )
Accum -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accum /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accum *= parseFloat(Readout);
else
Accum = parseFloat(Readout);
FKeyPad.ReadOut.value = Accum;
PendingOp = Op;
}
}
function Decimal () {
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear () {
Accum = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent () {
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accum);
}
// -->
</script>
</font></p>
<p></center>
</body>
</html>
C'est basique mais ca fonctionne, tu peux changer tout bien entendu mais le fonctionnement sera le même...
La création d'un site commence par la réflexion de son devenir...