Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
Texto de cambio de máquina de escribir

Tengo un sitio web en falla y estaba probando y jugando con algunos con código.

¡Decidí que quería intentar hacer texto de máquina de escribir!

Alguien en StackOverFlow me ayudó a resolverlo, pero ahora tengo otra pregunta.

Quiero hacer que el texto de la máquina de escribir cambie y cambie a otro conjunto de texto cuando vuelva a hacer clic en el botón.

No puedo hacer eso sin recargar toda la página o hacer que el sitio se recargue con código. ¿Alguien sabe otra forma?

Mi código:

 URL is being Deleted... <br> <progress></progress> <!DOCTYPE html> <html> <body> <br><br> <button onclick="typeWriter()">View Status</button> <p id="demo"></p> <script> var i = 0; var txt = randomText(); var speed = 50; function typeWriter() { if (i < txt.length) { document.getElementById("demo").innerHTML += txt[i]; i++; setTimeout(typeWriter, speed); } } function randomText() { //array splashes var say = []; say[0] = "Moving Core Files..."; say[1] = "Deleting JavaScript"; say[2] = "Uploading Data..."; say[3] = "Editing HTML..."; say[4] = "Disabling Server.js"; say[5] = "Deleting Cookies..."; say[6] = "Deleted Files (3/754)"; say[7] = "Attempting URL Shutdown"; say[8] = "Uploading Deletion Program!"; say[9] = "Deleting URL..."; say[10] = "Changing CSS"; say[11] = "Deleting Inside Fules..."; //pick a random greeting var howmany = 11; var bRand = 0; bRand = Math.random(); bRand = Math.floor(bRand * howmany); //prepare and docwrite the greeting sayWhat = say[bRand]; //direct type in html p element //document.getElementById("splash").innerHTML ='javascript:alert("' + '");' // I tried to make this work but it says no. return sayWhat; } </script> </body> </html> <script style="color:white" language="JavaScript" type="text/javascript"> //script to generate random greetings </script> <script style="color:white" type="text/javascript"> </script>

¡El código es lo que hace que la máquina de escribir funcione!

He estado buscando e investigando cómo hacerlo, pero no tuve la suerte de encontrar cómo hacer que cambiara el texto. El botón no escribirá un texto diferente.

un mejor por qué sería si alguien pudiera ayudarme a hacer que el texto cambie cada 10 segundos.
¿Alguien tiene alguna idea? No tengo ni idea de cómo hacer esto :(

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Quiero hacer que el texto de la máquina de escribir cambie y cambie a otro conjunto de texto cuando vuelva a hacer clic en el botón.

 let i = 0; const speed = 2; let txt = ''; const out = document.getElementById('demo'); function start() { demo.innerHTML = ''; console.log('click'); txt = randomText(); i = 0; typeWriter(); } function typeWriter() { if (i < txt.length) { document.getElementById("demo").innerHTML += txt[i]; i++; setTimeout(typeWriter, speed); } } function randomText() { //array splashes var say = []; say[0] = "Moving Core Files..."; say[1] = "Deleting JavaScript"; say[2] = "Uploading Data..."; say[3] = "Editing HTML..."; say[4] = "Disabling Server.js"; say[5] = "Deleting Cookies..."; say[6] = "Deleted Files (3/754)"; say[7] = "Attempting URL Shutdown"; say[8] = "Uploading Deletion Program!"; say[9] = "Deleting URL..."; say[10] = "Changing CSS"; say[11] = "Deleting Inside Fules..."; //pick a random greeting var howmany = 11; var bRand = 0; bRand = Math.random(); bRand = Math.floor(bRand * howmany); //prepare and docwrite the greeting sayWhat = say[bRand]; //direct type in html p element //document.getElementById("splash").innerHTML ='javascript:alert("' + '");' // I tried to make this work but it says no. return sayWhat; }
 <br> <progress></progress> <!DOCTYPE html> <html> <body> <br><br> <button onclick="start()">View Status</button> <p id="demo"></p> <script> </script> </body> </html> <script style="color:white" language="JavaScript" type="text/javascript"> //script to generate random greetings </script> <script style="color:white" type="text/javascript"> </script>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Por lo tanto, debe restablecer el tiempo de espera y debe restablecer sus variables

 var timer; var i; var txt; function typeWriter() { if (i < txt.length) { document.getElementById("demo").innerHTML += txt[i]; i++; timer = setTimeout(typeWriter, speed); } } function anotherSentence () { if (timer) window.clearTimeout(timer); i = 0; txt = randomText(); typeWriter(); } anotherSentence();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda