简体   繁体   English

如何使用javascript或jquery中的图片网址上传图片?

[英]How to upload an image using image url from web in javascript or jquery?

I have a page , I need to Add a Picture from the web using it's URL and display it in my page same as the below image using Jquery or Javascript. 我有一个页面,我需要使用它的URL从网上添加图片,并使用Jquery或Javascript将其显示在我的页面中,与下面的图片相同。

在此处输入图片说明

You need to have a textbox where you can enter the url for the image and a button to attach an event. 您需要有一个文本框,您可以在其中输入图像的URL和一个附加事件的按钮。

 var button = document.getElementById("button"), input = document.getElementById("input"), image = document.getElementById("image"), src; // button click event button.onclick = function(){ // in case you want to use somewhere else src = input.value; // set the image src to the input value image.src = src; } 
 <input id="input" type="text"/> <button id="button">click me</button> <img id="image" height="200px"/> 

  • It just updates the image 'src' attibute and shows the image. 它只是更新图像“ src”服饰并显示图像。 and which is not saved ,and its not performing like input type ='file'. 并且未保存,并且其性能不如输入类型='file'。

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

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