简体   繁体   中英

How do i get an image link to change live based on textbox?

i'd like a textbox to change the url of an img

Image Code

<img src="http://url.com/ text the user types">

All i want to happen is the img url to changed based on a textbox and for it to change live. it has to be appended onto another url like https://google.com/ + text

An example is https://webcode.tools/html-generator/image

 const textBox = document.getElementById('text-box'); const img = document.getElementById('image'); textBox.addEventListener('input', (e) => { img.src = `https://google.com/${e.target.value}` }) 
 <input type="text" id="text-box" placeholder="Enter pic url" /> <img src="" alt="your image" id="image" /> 

there you go

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM