简体   繁体   English

如何获取图像链接以根据文本框实时更改?

[英]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 我想要一个文本框来更改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. 我要做的只是根据文本框更改img url,并对其进行实时更改。 it has to be appended onto another url like https://google.com/ + text 必须将其附加到另一个网址(例如https://google.com/ +文本)上

An example is https://webcode.tools/html-generator/image 一个示例是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 你去

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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