js实现图片在线预览
Posted 八月长安个人专栏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js实现图片在线预览相关的知识,希望对你有一定的参考价值。
js在线预览图片
一、效果预览
二、实现代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js图片在线预览</title>
<script language=javascript>
function viewPic(obj)
var fileUrl=$(obj).attr("fileUrl");
var title=$(obj).attr("title");
$("#pic").attr("src",fileUrl);
$("#pictitle").html(title);
</script>
</head>
<body>
<input type="file" οnchange="previewFile()"><br>
<img src="" height="200" width="300" alt="Image preview..."/>
<div class="row">
<c:forEach items="$fileList " var="file" varStatus="status">
<div class="row" id="div$status.index+1 ">
<div class="col-md-4">
<div class="form-group" >
<label class="control-label col-md-4" style="font-weight:bold;padding-top:0px;">$status.index+1 .</label>
<c:choose>
<c:when test="$file.suffix == '.JPG' || file.suffix == '.bmp' || file.suffix == '.png'|| file.suffix == '.gif' || file.suffix == '.jpeg'|| file.suffix == '.pjpeg'|| file.suffix == '.jpg'">
$file.fileName <a title="$file.fileName " οnclick="viewPic(this)" data-toggle='modal' data-target='#large_pic' fileUrl="<%=baseUrl %>uploadfiles/$file.fileUrl " target=_blank>查看</a>
</c:when>
<c:otherwise>
无效文件
</c:otherwise>
</c:choose>
</div>
</div>
</div>
</c:forEach>
</div>
<!-- Modal 弹出框-->
<div class="modal fade bs-modal-lg in" id="large_pic" tabindex="-1" data-backdrop="static" data-keyboard="false" role="dialog" aria-hidden="false" >
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3 class="modal-title" id="pictitle"></h3>
</div>
<div class="modal-body">
<img src="" id="pic" style="width: 870px;">
</div>
</div>
</div>
</div>
</body>
</html>
以上是关于js实现图片在线预览的主要内容,如果未能解决你的问题,请参考以下文章
文档在线预览使用js前端实现wordexcelpdfppt 在线预览