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

126
Views
Mostrar dos tamaños diferentes de imagen cuando la URL se pega en el cuadro de texto

No puedo cambiar el tamaño de la imagen. Aquí está mi código

 document.getElementById('btn1').addEventListener('click', function(){ document.getElementById('photo').innerHTML = '<img src="'+ document.getElementById('imglink').value +'"?width=400&height=400&fit=crop"/>'; });
 <!DOCTYPE html> <html> <body> <form action="#" method="post"> <input type="url" name="imglink" id="imglink" placeholder="Insert image URL here" /><br> <input type="button" value="Show Image" id="btn1" /> </form> <div id="photo"></div> </body> </html>

Lo que quiero es que cuando pegue la URL, la imagen se mostrará en 2 divs diferentes y cambiará de tamaño automáticamente. Sin embargo, necesito dos tamaños diferentes de la imagen. El tamaño del primer div sería el número 1 y el segundo div sería el número 2. No sé cómo poner este tamaño en el código javascript.

  1. ?ancho=400&alto=400&ajuste=recortar
  2. ?ancho=800&alto=450&ajuste=recortar

¿Cómo puedo hacer eso?

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

0

Puede agregar valores para ancho y alto usando javascript como este:

 '<img src="'+ document.getElementById('imglink').value +'" width="400" height="400" fit="crop"/>'

Pruebe el fragmento a continuación:

 document.getElementById('btn1').addEventListener('click', function(){ // Image1 document.getElementById('image1').innerHTML = '<img src="'+ document.getElementById('imglink').value +'" width="400" height="400" fit="crop"/>'; // Image2 document.getElementById('image2').innerHTML = '<img src="'+ document.getElementById('imglink').value +'"width="800" height="450" fit="crop"/>'; });
 <!DOCTYPE html> <html> <body> <form action="#" method="post"> <input type="url" name="imglink" id="imglink" placeholder="Insert image URL here" /><br> <input type="button" value="Show Image" id="btn1" /> </form> <div id="image1"></div> <div id="image2"></div> </body> </html>

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!