18910140161

JavaScript-当我粘贴链接时如何更改图像URL-堆栈溢出

顺晟科技

2022-10-18 14:01:26

78

我在JavaScript中工作,基本上我想显示图像,当用户从设备中选择图像时,图像必须更改我在JavaScript文件中使用的代码。

<代码>函数changeProfile(){var location=document.getElementById(";profileLocation";);alert(location.value);var image=document.getElementById(";ProfileAAImage";);image.SRC(location.value);}
我在HTML文件中编写

的代码是

<代码><;DIV类=";行";>;<;DIV类=";col-MD-3表格-组";style=";左填充:7%;";>;<;IMG ID=";ProfileImage";style=";border-radius:200px;";SRC=";images/interne/areab%20suhaib.JPG";类=";IMG-thumbnail";宽度=100高度=";100";>;<;/DIV>;<;DIV类=";COL-MD-9表组MT-3 MT-MD-0";style=";顶部填充:5%;";>;<;输入类型=";文件";名称=";文件";类=";表单控制";ID=";配置文件位置";onclick=";changeProfile()";OnKeyUp=";changeProfile()";Placeholder=";选择配置文件图像";必需>;<;/DIV>;<;/DIV>;
我做

什么来完成所需的任务。


顺晟科技:

function changeProfile(){ var location = document.getElementById("profileLocation"); alert(location.value); var image = document.getElementById("profileAAImage"); image.src(location.value); } 更改为<div class="row"> <div class="col-md-3 form-group" style="padding-left: 7%;"> <img id="profileImage" style="border-radius: 200px;" src="images/interne/areab%20suhaib.jpg" class="img-thumbnail" width="100" height="100" > </div> <div class="col-md-9 form-group mt-3 mt-md-0" style="padding-top: 5%;"> <input type="file" name="file" class="form-control" id="profileLocation" onclick="changeProfile()" onkeyup="changeProfile()" placeholder="select profile image" required> </div> </div> 以获取所选文件。

<代码>函数changeProfile(){var location=document.getElementById(“ profileLocation ”);Var image=document.getElementById(“ ProfileImage ”);image.SRC=window.URL.createObjectURL(location.files[0]);}
<代码><;DIV类=“ row ”>;<;DIV Class=“ col-MD-3 form-group ” style=“ padding-left:7%;”>;<;IMG ID=“ ProfileImage ” style=“ border-radius:200px;” SRC=“ images/interne/areab%20suhaib.JPG ” Class=“ IMG-thumbnail ” width=“ 100 ” height=“ 100 ”>;<;/DIV>;<;DIV Class=“ col-MD-9 form-group mt-3 mt-MD-0 ” style=“ padding-top:5%;”>;<;INPUT TYPE=“ file ” NAME=“ file ” CLASS=“ form-control ” ID=“ ProfileLocation ” ONCHANGE=“ changeProfile()” PLACEHOLDER=“选择配置文件映像”必需>;<;/DIV>;<;/DIV>;

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航