700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > javascript实现input file上传图片预览效果

javascript实现input file上传图片预览效果

时间:2022-01-03 14:09:10

相关推荐

javascript实现input file上传图片预览效果

web前端|js教程

javascript input file

web前端-js教程

本文实例介绍了javascript实现input file上传图片预览效果的详细代码,分享给大家供大家参考,具体内容如下

dz论坛视频源码,vscode的基础教程网站,ubuntu升级不过,tomcat登录密码加密,1688数据爬虫,php 图形编程,seo推广公司报价多少钱lzw

运行效果图:

易语言流程控制源码,ubuntu公网域名绑定,tomcat最大并发配置,爬虫谷歌翻译,php 串口数据怎么导入,彩虹seolzw

适合做流量的网站源码,ubuntu里窗口太大,tomcat免安装版区别,论坛 图片 爬虫,php登录界面怎么登陆,湛江seo策略lzw

具体实现代码:

.imgbox,.imgbox1 { float: left; margin-right: 20px; margin-top: 20px; position: relative; width: 182px; height: 142px; border: 1px solid red; overflow: hidden; } .imgbox1{border: 1px solid blue; } .imgnum{ left: 0px; top: 0px; margin: 0px; padding: 0px; } .imgnum input,.imgnum1 input { position: absolute; width: 182px; height: 142px; opacity: 0; } .imgnum img,.imgnum1 img { width: 100%; height: 100%; } .close, .close1 { color: red; position: absolute; left: 170px; top: 0px; display: none; }

X

X

X

X

X

X

X

X

X

X

$(function() { $(".filepath").on("change",function() { alert($(.imgbox).length); var srcs = getObjectURL(this.files[0]); //获取路径 $(this).nextAll(".img1").hide(); //this指的是input $(this).nextAll(".img2").show(); //fireBUg查看第二次换图片不起做用 $(this).nextAll(.close).show(); //this指的是input $(this).nextAll(".img2").attr("src",srcs); //this指的是input $(this).val(\); //必须制空 $(".close").on("click",function() { $(this).hide(); //this指的是span $(this).nextAll(".img2").hide(); $(this).nextAll(".img1").show(); }) }) })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 };$(function() { $("#img").on("change",".filepath1",function() { //alert($(.imgbox1).length); var srcs = getObjectURL(this.files[0]); //获取路径 alert(srcs); //this指的是input /* $(this).nextAll(".img22").attr("src",srcs); //this指的是input $(this).nextAll(".img22").show(); //fireBUg查看第二次换图片不起做用*/ var htmlImg=

+

+\+X+\+\+

+

; $(this).parent().parent().before(htmlImg); $(this).val(\); //必须制空 $(this).parent().parent().prev().find(".img11").hide(); //this指的是input $(this).parent().parent().prev().find(.close1).show(); $(".close1").on("click",function() { $(this).hide(); //this指的是span $(this).nextAll(".img22").hide(); $(this).nextAll(".img11").show(); if($(.imgbox1).length>1){$(this).parent().parent().remove(); } }) }) })

更多javascript实现input file上传图片预览效果相关文章请关注PHP中文网!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。