Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda