Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Hacer que un botón div actúe como un botón de archivo de entrada

Así que quiero tener un div que actúe como botón/entrada con tipo de archivo que me permita cargar archivos, pero no sé cómo hacerlo.

Vi algunas respuestas, pero usaban Jquery, pero quiero JS simple.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí hay una solución lista para usar que encontré al escribir su pregunta en la barra de búsqueda del desbordamiento de pila.

 function promptFile(contentType, multiple) { var input = document.createElement("input"); input.type = "file"; input.multiple = multiple; input.accept = contentType; return new Promise(function(resolve) { document.activeElement.onfocus = function() { document.activeElement.onfocus = null; setTimeout(resolve, 500); }; input.onchange = function() { var files = Array.from(input.files); if (multiple) return resolve(files); resolve(files[0]); }; input.click(); }); } function promptFilename() { promptFile().then(function(file) { document.querySelector("span").innerText = file && file.name || "no file selected"; }); }
 <button onclick="promptFilename()">Open</button> <span></span>

Enlace de referencia: ¿Cómo abrir el cuadro de diálogo Seleccionar archivo a través de js?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!