猿问

webuploader的问题

webuploader的问题,上传到后台没有问题,后台是使用php,但是现在想问的问题是怎么把数据放到容器里,数据可以取的出来,但是就是不知道要放到哪里。

要放到哪个位置呢?大神帮帮忙,谢谢。
是从数据库读取出来的预览效果


不负相思意
浏览 782回答 2
2回答

繁星淼淼

虽然不是很明白题主的意思,但是如过图片少,想要预览的效果可以使用FileReader对象,将图片的base64保存到localstorage,刷新后再取出来显示,个人想法<input id="upload" type='file' onchange="preview(this.files)">&nbsp; &nbsp; &nbsp; &nbsp; <div id="uploadBtn">submit</div>&nbsp; &nbsp; &nbsp; &nbsp; <script type="text/javascript">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; files = localStorage.getItem('path');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function preview(files) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0;i < files.length;i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var reader = new FileReader();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reader.onload = function(event) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; localStorage.setItem('path',this.result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reader.readAsDataURL(files[i]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(files) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var image = new Image();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image.width = 100;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image.src = files;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.body.appendChild(image);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; </script>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答