Ver Mensaje Individual
  #9 (permalink)  
Antiguo 20/11/2017, 07:12
Berman
 
Fecha de Ingreso: abril-2016
Mensajes: 19
Antigüedad: 8 años, 1 mes
Puntos: 1
Respuesta: Al volver a cargar el script se vuelven a iniciar las variables

Perdón por mi incompetencia, pero al poner el código en netbeans no me funciona.

lo he puesto en un archivo php así:
Código PHP:
Ver original
  1. <html>
  2.     <head>
  3.         <meta charset="UTF-8">
  4.         <title>Contador</title>
  5.     </head>
  6.     <body bgcolor="#FE9A2E">
  7.         <div>DADO: <span id="dado"></span></div>
  8.         <div>Contador: <span id="contador">0</span></div>
  9.     <center><button onclick="dado()">Dado</button></center>
  10.     <script>
  11.         function dado() {
  12.             var contador = $("#contador").html();
  13.             var dadorand = Math.floor((Math.random() * 6) + 1);
  14.             $("#dado").html(dadorand);
  15.             $("#contador").html(parseInt(contador) + parseInt(dadorand));
  16.  
  17.     </script>
  18. </body>
  19. </html>

es así como se hace, hoy que hacerlo en un archivo JS? Muchas gracias