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

249
Vistas
Recibiendo otro valor js del atributo html obteniendo un error

Aquí está mi código,

 <section class="page-section portfolio" id="portfolio"> <div class="container"> <center> <h4 id="randomText"></h4> <input type="text" class="form-control mb-2" placeholder="Enter Text " id="enter_text" required autofocus> <button id='verify_id' class="btn btn-primary btn-lg">Verify</button> <br><br> <p id="text_showing"></p> </center> </div> </section> <script> const characters ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; function generateString() { var length = 8; let result = ' '; const charactersLength = characters.length; for ( let i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result;

}

 function show_text(){ document.getElementById('randomText').innerHTML=generateString(); } show_text() </script> <script defer> $(document).ready(function(){ $("#verify_id").click(function(){ var text=$('#enter_text').val(); var text1=$('#randomText').text(); if (text == text1){ $('#text_showing').text("You have successfully verified the text").css({ 'color': 'green', 'font-size': '150%' }); } else{ $('#text_showing').text("Given text and Input text not matching ").css({ 'color': 'red', 'font-size': '150%' }); } }); }); </script>

Ahora, el problema después de ingresar el texto correcto en el campo de entrada aparece el mensaje de error "El texto dado y el texto de entrada no coinciden", no puedo resolver el problema, ¿alguien puede ayudarme a resolver el problema?

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

0

El problema es el espacio en let result = ' '; . Elimina el espacio ' ' y funciona.

Manifestación

 const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; function generateString() { var length = 8; let result = ''; const charactersLength = characters.length; for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } function show_text() { document.getElementById('randomText').innerHTML = generateString(); } show_text() $(document).ready(function() { $("#verify_id").click(function() { var text = $('#enter_text').val(); var text1 = $('#randomText').text(); if (text == text1) { $('#text_showing').text("You have successfully verified the text").css({ 'color': 'green', 'font-size': '150%' }); } else { $('#text_showing').text("Given text and Input text not matching ").css({ 'color': 'red', 'font-size': '150%' }); } }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <section class="page-section portfolio" id="portfolio"> <div class="container"> <center> <h4 id="randomText"></h4> <input type="text" class="form-control mb-2" placeholder="Enter Text " id="enter_text" required autofocus> <button id='verify_id' class="btn btn-primary btn-lg">Verify</button> <br><br> <p id="text_showing"></p> </center> </div> </section>

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