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

248
Vistas
¿Cómo concatenar usando getElementbyID en un elemento de lista?

aquí está el código

 <h1>Timeworn Kumbhiraskin Maps</h1> <label for="room">What chamber did you reach?</label> <select id="room"> <option value="none">No portal</option> <option value="first">First Chamber</option> <option value="second">Second Chamber</option> <option value="third">Third Chamber</option> <option value="fourth">Fourth Chamber</option> <option value="fifth">Final Chamber</option> </select> <ul id="percentages"> <li id="np">No portal: </li> <li id="firstC">First Chamber: </li> <li id="secondC">Second Chamber: </li> <li id="thirdC">Third Chamber: </li> <li id="fourthC">Fourth Chamber:</li> <li id="fifthC">Final Chamber: </li> </ul> </body> </html>
 var totalMaps = 0; var pPortal = 0; var pFirst = 0; var pSecond = 0; var pThird = 0; var pFourth = 0; var pFifth = 0; window.onload = function(){ document.getElementById("np").value += string(pPortal); document.getElementById("firstC").value += string(pFirst); document.getElementById("secondC").value += string(pSecond); document.getElementById("thirdC").value += string(pThird); document.getElementById("fourthC").value += string(pFourth); document.getElementById("fifthC").value += string(pFifth); }

Básicamente, solo estoy teniendo problemas con el javascript. Quiero mostrar las variables de javascript en la lista, pero no se muestra. ¿Alguna ayuda? ¿Estoy haciendo algo mal? Probé algunos métodos diferentes y busqué en línea, pero parece que nadie tiene la respuesta que estoy buscando.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Si desea convertir una variable en una cadena, tiene para usted la función String() (sensible a mayúsculas y minúsculas). También te perdiste la parte que decía innerHTML. Esto es trabajo para mí

 <body> <ul id="percentages"> <li id="np">No portal: </li> <li id="firstC">First Chamber: </li> <li id="secondC">Second Chamber: </li> <li id="thirdC">Third Chamber: </li> <li id="fourthC">Fourth Chamber:</li> <li id="fifthC">Final Chamber: </li> </ul> </body> <style> body {padding: 0.5rem 1rem;} </style> <script> let totalMaps = 0; let pPortal = 0; let pFirst = 0; let pSecond = 0; let pThird = 0; let pFourth = 0; let pFifth = 0; window.onload = function(){ document.getElementById("np").innerHTML += String(pPortal); document.getElementById("firstC").innerHTML += String(pFirst); document.getElementById("secondC").innerHTML += String(pSecond); document.getElementById("thirdC").innerHTML += String(pThird); document.getElementById("fourthC").innerHTML += String(pFourth); document.getElementById("fifthC").innerHTML += String(pFifth); } </script>
about 4 years ago · Santiago Trujillo Denunciar

0

Prueba esto

 document.getElementById('np').innerHTML += pPortal;

... etc. El operador JS + convierte automáticamente su tipo de número en una cadena en este caso.

about 4 years ago · Santiago Trujillo 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