简体   繁体   English

如何使用jQuery或Javascript上传图片

[英]How to make image upload using jQuery or Javascript

I couldn't do this because my javascript part was not good. 我无法执行此操作,因为我的javascript部分不好。 I have a design in mind. 我有一个设计思路。 When you click the button and upload the picture, the picture will appear in that circle. 当您单击按钮并上传图片时,图片将出现在该圆圈中。 At the same time if you want to remove the cross button. 同时如果要删除十字按钮。 Theme screenshot 主题截图

<div class="upload">
<img src="images/upload.png" class="uploadImage" alt="">
<input type="file" class="imageUpload">

<style>
.upload{
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 3px dashed #ddd;
}
input[type="file"].imageUpload{
    cursor: pointer;
    font: 300 14px sans-serif;
    color:#9e9e9e;
    width: 128px;
    height: 128px;
    border-radius: 50%;
    background:  rgba(0, 0, 0, 0);
    position: relative;
    z-index: 2;
    display: block;
    margin-top: -2px;
}
input[type="file"].imageUpload::-webkit-file-upload-button{
    display: none
}
img.uploadImage{
    position: absolute;
    margin-top: 41px;
    z-index: 1;
    left: 70px;
    width: 39px;
}
</style>

There is a design for the album page. 相册页面有一个设计。 I'm gonna use a design here. 我要在这里使用设计。 Click on the button and the image after the bear will be listed next to the size button. 单击按钮,熊之后的图像将显示在尺寸按钮旁边。 At the same time the cross button can be removed at any time. 同时,可以随时删除十字按钮。 Theme screenshot 主题截图

I would appreciate it if you tell me with a simple design. 如果您以简单的设计告诉我,我将不胜感激。 It's like I can handle it myself if I understand your logic. 如果我了解您的逻辑,就好像我可以自己处理。

Somewhat like you want 有点像你想要的

<form>
  <input required type="file" name="fileToUpload" multiple data-preview-to="#preview" />
  <div id=preview></div>
  <input type=hidden name="who-sent" value="jake sent me">
  <button>submit</button>
</form>

$($(this).data("preview-to")).html($.map(this.files, function(f) {
    return `<figure>
   <img src="${URL.createObjectURL(f)}">
   <figcaption><input type=checkbox checked> ${f.name}</figcaption>
  </figure>`
  }))

JSFiddle Example JSFiddle示例

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

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