elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web (Moderador: #!drvy)
| | |-+  [SRC] [javascript] Calculadora básica estilo Windows
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [SRC] [javascript] Calculadora básica estilo Windows  (Leído 3,217 veces)
Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
[SRC] [javascript] Calculadora básica estilo Windows
« en: 16 Octubre 2012, 11:42 am »

Código
  1.  
Sí, lo sé, las calculadoras están muy vistas, pero como lo tuve que hacer para clase de paso lo pongo aquí.

Código
  1. <html>
  2. <head>
  3. <style>
  4. input{
  5. width: 42px;
  6. }
  7.  
  8. #logs, #res, #igual{
  9. text-align: right;
  10. width: 180px;
  11. }
  12.  
  13. .op, #igual{
  14. text-align: center;
  15. }
  16. </style>
  17.  
  18. <script language="javascript">
  19. function getLastchar(){
  20. var mylogs = document.calc.logs.value;
  21. var len = mylogs.length;
  22.  
  23. if (len){
  24. return mylogs[len - 1];
  25. }
  26.  
  27. return "";
  28. }
  29.  
  30. function anadir(x){
  31. var logstext = document.calc.logs;
  32. var restext = document.calc.res;
  33.  
  34. if (logstext.value == "" && restext.value != ""){
  35. restext.value = "";
  36. }
  37.  
  38. if ((". ".indexOf(getLastchar()) > -1 && isNaN(x)) == false){
  39. if (x.indexOf(" ") > -1){
  40. calcular();
  41. }
  42.  
  43. logstext.value += x;
  44. }
  45. }
  46.  
  47. function quitar(){
  48. var logstext = document.calc.logs;
  49. var num = (getLastchar() == " ") ? 3: 1;
  50.  
  51. logstext.value = logstext.value.substring(0, logstext.value.length - num);
  52. }
  53.  
  54. function calcular() {
  55. document.calc.res.value = eval(document.calc.logs.value);
  56. }
  57.  
  58. function getResult(){
  59. if (getLastchar() == " "){
  60. document.calc.res.value = "Syntax error";
  61. } else {
  62. calcular();
  63. document.calc.logs.value = "";
  64. }
  65. }
  66. </script>
  67. </head>
  68.  
  69. <body>
  70. <form name="calc">
  71. <input type="text" id="logs" readonly="true"/>
  72. <br />
  73. <input type="text" id="res" readonly="true"/>
  74. <br />
  75.  
  76. <input type="button" value="1" onclick="anadir('1')" />
  77. <input type="button" value="2" onclick="anadir('2')" />
  78. <input type="button" value="3" onclick="anadir('3')" />
  79. <input type="button" value="&larr;" onclick="quitar()" />
  80. <br />
  81.  
  82. <input type="button" value="4" onclick="anadir('4')" />
  83. <input type="button" value="5" onclick="anadir('5')" />
  84. <input type="button" value="6" onclick="anadir('6')" />
  85. <input type="button" value="-" onclick="anadir(' - ')" />
  86. <br />
  87.  
  88. <input type="button" value="7" onclick="anadir('7')" />
  89. <input type="button" value="8" onclick="anadir('8')" />
  90. <input type="button" value="9" onclick="anadir('9')" />
  91. <input type="button" value="+" onclick="anadir(' + ')" />
  92. <br />
  93.  
  94. <input type="button" value="0" onclick="anadir('0')" />
  95. <input type="button" value="." onclick="anadir('.')" />
  96. <input type="button" value="*" onclick="anadir(' * ')" />
  97. <input type="button" value="/" onclick="anadir(' / ')" />
  98. <br />
  99.  
  100. <input type="button" id="igual" value="=" onclick="getResult()" />
  101. </form>
  102. </body>
  103. </html>

DoEvents! :P


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Calculadora básica by swik
Scripting
.:Swik:. 1 2,846 Último mensaje 20 Abril 2010, 02:49 am
por BloodyDark
[Aporte] Calculadora estilo windows en VB6 (Muy basica y noob)
Programación Visual Basic
Dracomega 4 2,772 Último mensaje 2 Junio 2010, 22:34 pm
por Dracomega
Calculadora básica con interfaz [Win API][Terminada]
Programación C/C++
Alien-Z 1 6,206 Último mensaje 26 Septiembre 2011, 14:52 pm
por тαптяα
Problema con calculadora basica!!!!!!!!!!
Programación C/C++
prometheus48 4 2,995 Último mensaje 9 Octubre 2011, 14:48 pm
por prometheus48
Ayuda con calculadora básica en C
Programación C/C++
wazausky 2 2,256 Último mensaje 12 Marzo 2013, 03:03 am
por rir3760
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines