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

145
Visualizações
¿Cómo puedo cambiar el nombre de la etiqueta cuando se selecciona el archivo?

HTML se da a continuación-

 <input type="file" class="custom-file-input" accept="image/*" onchange="loadFile(event)" id="customFile"> <label class="custom-file-label" id="change" for="customFile">Choose File</label><br><br> <img width="150px" id="output" src="#"/>

El guión se da a continuación-

 var loadFile = function(event) { var output = document.getElementById('output'); output.src = URL.createObjectURL(event.target.files[0]); output.onload = function() { URL.revokeObjectURL(output.src) // free memory } };

Mi código puede mostrar la imagen seleccionada pero también quiero cambiar el texto de la etiqueta al nombre de la imagen seleccionada

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

La lógica para cambiar el texto de la etiqueta se puede escribir en el evento de cambio. Verifique el siguiente fragmento de evento,

 document.getElementById('customFile').onchange = function() { // code to change the label text var fullName = getFileName(document.getElementById('customFile').value); document.getElementById("change").innerHTML= fullName; }; var getFileName = function(fullPath) { if (!fullPath) return null; var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/')); var filename = fullPath.substring(startIndex); if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) { return filename.substring(1); } return null; }

Para obtener más información sobre cómo obtener el nombre del archivo, consulte https://stackoverflow.com/a/857662/17542117

about 4 years ago · Juan Pablo Isaza Relatório

0

Var name = document.getElementById("customFile").value;

Usar

 document.getElementById("Change").innerHTML = name

Corrija la ortografía.

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