如何制作多个用户编辑资料

发布于 2025-02-06 00:50:46 字数 1826 浏览 3 评论 0原文

我在创建带有用户变化的个人资料图片的HTML网站方面遇到了麻烦。例如,能够在员工配置文件上上传和更改您的个人资料图片。我已经尝试了许多方法,所以我真的不能放下任何代码进行修订,但这是我认为应该有效的方法:

var loadFile = function(event) {
  var image = document.getElementById("output");
  image.src = URL.createObjectURL(event.target.files[0]);
}
.profile-pic {
  color: transparent;
  transition: all 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.profile-pic input {
  display: none;
}

.profile-pic img {
  position: relative;
  object-fit: cover;
  box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.12) !important;
  z-index: 0;
}

.profile-pic .-label {
  cursor: pointer;
  position: absolute;
  bottom: 0;
}

.profile-pic:hover span {
  background-color: rgba(0, 0, 0, 0.8);
  color: #fafafa;
  transition: background-color 0.2s ease-in-out;
  display: inline-block;
  padding: 0.2em;
  height: 2em;
  text-align: center;
}
<div class="profile-pic">
  <img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
  <label for="file" class="-label">
                <span>Change Photo</span>
            </label>
  <input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>
<hr>
<div class="profile-pic">
  <img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
  <label for="file" class="-label">
                   <span>Change Photo</span>
                </label>
  <input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>

I have been having trouble with creating an HTML site with a user-changeable profile picture. For example, being able to upload and change your profile picture on employee profiles. I've tried many methods, so I really can't put any code down for revision, but here's what I thought should work:

var loadFile = function(event) {
  var image = document.getElementById("output");
  image.src = URL.createObjectURL(event.target.files[0]);
}
.profile-pic {
  color: transparent;
  transition: all 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.profile-pic input {
  display: none;
}

.profile-pic img {
  position: relative;
  object-fit: cover;
  box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.12) !important;
  z-index: 0;
}

.profile-pic .-label {
  cursor: pointer;
  position: absolute;
  bottom: 0;
}

.profile-pic:hover span {
  background-color: rgba(0, 0, 0, 0.8);
  color: #fafafa;
  transition: background-color 0.2s ease-in-out;
  display: inline-block;
  padding: 0.2em;
  height: 2em;
  text-align: center;
}
<div class="profile-pic">
  <img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
  <label for="file" class="-label">
                <span>Change Photo</span>
            </label>
  <input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>
<hr>
<div class="profile-pic">
  <img src="img/ananthu-1.jpg" id="output" style="width:120px; height:120px;">
  <label for="file" class="-label">
                   <span>Change Photo</span>
                </label>
  <input type="file" accept="image/*" id="file" onchange="loadFile(event)">
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏璃陌 2025-02-13 00:50:46

现在,您更改IMG标签“ ID”。并添加一个参数。

**HTML**
<div class="profile-pic">
    <img src="img/ananthu-1.jpg" id="output1"  style="width:120px; height:120px;"> 
        <label for="file" class="-label">
            <span>Change Photo</span>
        </label>
        <input type="file" accept="image/*" id="file" onchange="loadFile(event,1)">
                                
 </div>
  <hr>
      <div class="profile-pic">
        <img src="img/ananthu-1.jpg" id="output2"  style="width:120px; height:120px;"> 
            <label for="file" class="-label">
               <span>Change Photo</span>
            </label>
            <input type="file" accept="image/*" id="file" onchange="loadFile(event,2)">
                                
      </div>

并更改输入文件 - 显示:块。

**CSS**
.profile-pic input {
  display: block;
}

**JS**
var loadFile = function(event,id) {
  var image = document.getElementById("output"+id);
  image.src = URL.createObjectURL(event.target.files[0]);
}

now you change img tag 'id'. And add a parameter.

**HTML**
<div class="profile-pic">
    <img src="img/ananthu-1.jpg" id="output1"  style="width:120px; height:120px;"> 
        <label for="file" class="-label">
            <span>Change Photo</span>
        </label>
        <input type="file" accept="image/*" id="file" onchange="loadFile(event,1)">
                                
 </div>
  <hr>
      <div class="profile-pic">
        <img src="img/ananthu-1.jpg" id="output2"  style="width:120px; height:120px;"> 
            <label for="file" class="-label">
               <span>Change Photo</span>
            </label>
            <input type="file" accept="image/*" id="file" onchange="loadFile(event,2)">
                                
      </div>

and change the input file - display: block.

**CSS**
.profile-pic input {
  display: block;
}

**JS**
var loadFile = function(event,id) {
  var image = document.getElementById("output"+id);
  image.src = URL.createObjectURL(event.target.files[0]);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文