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

眉间皱痕 提交于 2020-01-07 04:15:39

问题


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.


回答1:


You need to have a textbox where you can enter the url for the image and a button to attach an event.

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"/>



回答2:


  • It just updates the image 'src' attibute and shows the image. and which is not saved ,and its not performing like input type ='file'.


来源:https://stackoverflow.com/questions/30709270/how-to-upload-an-image-using-image-url-from-web-in-javascript-or-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!