javascript - 粘贴链接时如何更改图片网址
问题描述
我在javascript中工作基本上我想在用户从设备中选择图像时显示图像图像必须更改我在javascript文件中使用的代码是
function changeProfile(){
var location = document.getElementById("profileLocation");
alert(location.value);
var image = document.getElementById("profileAAImage");
image.src(location.value);
}
我在 html 文件中编写的代码是
<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>
我做什么来完成所需的任务。
解决方案
更改location.value
为location.files[0]
获取所选文件。
function changeProfile() {
var location = document.getElementById("profileLocation");
var image = document.getElementById("profileImage");
image.src = window.URL.createObjectURL(location.files[0]);
}
<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" onchange="changeProfile()" placeholder="select profile image" required>
</div>
</div>
推荐阅读
- svn - 加载修订更改 svn:author
- c# - 在使用它的应用程序关闭后持有 WCF TCP 端口的系统进程
- android - OnverificationCompleted() 被调用但没有收到任何 otp
- python - 导入另一个python文件时Django runserver没有运行
- vb.net - Vb-net 在准备表格时隐藏布局
- php - PHP 错误视频无法使用过期/签名的视频嵌入 url 播放
- sql - 获取两个表之间的完全匹配
- scala - 从 scalatest 生成 XML 报告时,有没有办法让“给定”、“何时”、“那么”可见?
- angular - 将文本作为文件发送到具有其他值的后端
- php - 保存取决于所选字段的数据