Pseudo Mot de passe
fleche Inscription
fleche Mot de passe oublié ?
Informations Générales
Chargement en cours...
Nombre de Visites fleche [ 1 036 254 ]
Votre IP fleche [ 38.107.191.117 ]
Vous êtes ici : Home Page Dossiers Trucs et astuces (JavaScript) Calculatrice
Imprimer le document Version Imprimable

Informations Générales

[425] Posts sur le forum
[453] Membres inscrits
Il y a en ligne :
arrow 0 Membre
arrow 4 Invités
fled Membre en ligne:
Aucun

Partenariat

Partenariat Vous pouvez aider ce site à évoluer, en contribuant à son développement. Proposez vos idées de cours et/ou dossiers.
Rendez-vous dans « Partenariat » pour en savoir plus.


Publicité


Prestataire

N°1 de l'hébergement, location de serveurs, nom de domaines et téléphonie.
(OVH est recommandé par Webelix.net)

www.

Nos Partenaires

JavaScript - Calculatrice

Auteur : 3L!X | Créé le : 26/12/2006 à 18H00

Voici une calculatrice avec 4 fonctions.


Entre les balises <HEAD> et </HEAD> :

<script type="text/javascript">
<!--
var valor=0;
var stock="",stock2="";
var ope=false,plu=false,moi=false,mul=false,div=false,flag_egal=false;
function affiche(res)
{
  document.calc.ecran.value=res;
}
function touche(param)
{
  if(param=="12")
  {
    valor=0;document.calc.ecran.value="0";stock="";stock2="";
    raz_flags();ope=false;
  } 
  if((param>=0)&&(param<=10))
  {
    if(flag_egal){raz_flags();valor=0;ope=false;stock="";}
    if(ope==true)
    {
      if(param==10) stock2+='.'; else stock2+=param;
      affiche(stock2);
      if(plu) valor=(stock*1)+(stock2*1);
      if(moi) valor=(stock*1)-(stock2*1);
      if(mul) valor=(stock*1)*(stock2*1);
      if(div) valor=(stock*1)/(stock2*1);
    }
    else 
    {
      if(param==10) stock+='.';else stock+=param;
      affiche(stock);
    }
  }
if(param==13) {raz_flags();plu=true;if(stock2!="") inter();ope=true;}
if(param==14) {raz_flags();moi=true;if(stock2!="") inter();ope=true;} 
if(param==15) {raz_flags();mul=true;if(stock2!="") inter();ope=true;}
if(param==16) {raz_flags();div=true;if(stock2!="") inter();ope=true;} 
if(param==17) {inter();flag_egal=true;} 
}
function raz_flags()
{
  plu=false;moi=false;mul=false;div=false;flag_egal=false;
}
function inter()
{
  affiche(valor);stock=valor;stock2="";
} 
//-->
</script>

Balise <BODY> :

Rien

Entre les balises <BODY> et </BODY> :

<form name="calc">
<table cellspacing="0" cellpadding="2" align="center" style="border: 1px solid #222;background: #eee">
<tr><td align="center" style="background: #aaa"><br />
	<input type="text" name="ecran" value="0" size="12" maxlength="12" style="font-weight: bold;text-align: right;background: #E5ECE5" />
</td></tr>
<tr><td align="center">
	<input type="button" name="C" value="C" onclick="touche(12)" style="width: 100px" />
</td></tr>
<tr><td align="center">
	<input type="button" value="7" onclick="touche(7)" style="width: 25px" />
	<input type="button" value="8" onclick="touche(8)" style="width: 25px" />
	<input type="button" value="9" onclick="touche(9)" style="width: 25px" />
	<input type="button" name="/" value="/" onclick="touche(16)" style="width: 25px" />
</td></tr>
<tr><td align="center">
	<input type="button" value="4" onclick="touche(4)" style="width: 25px" />
	<input type="button" value="5" onclick="touche(5)" style="width: 25px" />
	<input type="button" value="6" onclick="touche(6)" style="width: 25px" />
	<input type="button" name="*" value="x" onclick="touche(15)" style="width: 25px" />
</td></tr>
<tr><td align="center">
	<input type="button" value="1" onclick="touche(1)" style="width: 25px" />
	<input type="button" value="2" onclick="touche(2)" style="width: 25px" />
	<input type="button" value="3" onclick="touche(3)" style="width: 25px" />
	<input type="button" name="-" value="-" onclick="touche(14)" style="width: 25px" />
</td></tr>
<tr><td align="center">
	<input type="button" value="0" onclick="touche(0)" style="width: 25px" />
	<input type="button" name="." value="." onclick="touche(10)" style="width: 25px" />
	<input type="button" value="=" onclick="touche(17)" style="width: 25px" />
	<input type="button" name="+" value="+" onclick="touche(13)" style="width: 25px" />
</td></tr>
</table>
</form>

[0] commentaire - Voir/EditerAjout commentaire

Haut de page