分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

form表单,上传图片及展示

发布时间:2023-09-06 02:14责任编辑:傅花花关键词:上传图片form表单
.comment_con .file{position: relative;top:2rem;z-index: 999;width: 5rem;height: 5rem;background: red;opacity: 0}.comment_con .upload{width: 5rem;height: 5rem;font-size: 4em;font-weight:lighter;line-height: 5rem;text-align: center;position: relative;top:-3rem;z-index: -1;background: #dfdbdc;}.show img{width: 46%;height: 5rem;margin: 0.3rem;}
<form action="" enctype="multipart/form-data">  <div class="show"><!-- <img src="" > -->  </div>  <div>    <input type="file" name="file" class="file" id="file" onchange="changepic(this)">    <div style="" class="upload">+</div>  </div></form>
<script>var show=document.querySelector(‘.show‘)var show_img=show.getElementsByTagName(‘img‘)[0]function changepic(obj) { ???var newsrc=getObjectURL(obj.files[0]); ???var img=document.createElement(‘img‘) ???show.appendChild(img) ???img.src=newsrc ???????}function getObjectURL(file) { ???????????var url = null ; ???????????if (window.createObjectURL!=undefined) { ????????????????url = window.createObjectURL(file) ; ???????????} else if (window.URL!=undefined) { ????????????????url = window.URL.createObjectURL(file) ; ???????????} else if (window.webkitURL!=undefined) { ????????????????url = window.webkitURL.createObjectURL(file) ; ???????????} ???????????return url ; ??????}</script> ????????

 上传图片之前的效果图如下:

上传图片之后的效果图如下:

只是简单的做了上传的处理,没有做删除操作

form表单,上传图片及展示

原文地址:https://www.cnblogs.com/naturl/p/9650980.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved